Ceviz Forum

Geri Dön   Ceviz Forum > Programlama > Pascal / Delphi / Delphi.NET

Cevapla
 
LinkBack Seçenekler
Eski 08/05/2008, 23:25   #1 (permalink)
Üye
 
civil Adlı Üyenin Profil Grafiği
 
Üyelik Tarihi: 04/2007
Mesaj: 461
Varsayılan Timer:Settimer

Delphi deki hazır timer ı kullanmak yerine windowsun settimer apisini kullanarak timer oluşturmak aynı şeymidir ... Aralarındaki fark nedir hangisi exe yi daha az şişirir yorumlarınızı bekliyorum
__________________
Yorum Yapmak Olayları Sadece Kenardan İzleyenlerin Lüksüdür
civil hatta değil   Alıntı Yaparak Yanıtla
Eski 09/05/2008, 00:10   #2 (permalink)
Kodlarım, Canlarım...
 
cemaliozan Adlı Üyenin Profil Grafiği
 
Üyelik Tarihi: 05/2005
Yer: » Delphi Bölümü «
Mesaj: 1,677
Varsayılan

SetTimer bir fonksiyonun belli bir süre bitiminde çalıştırılmasını sağlar. Delphi'deki Timer nesnesi de aslında SetTimer kullanır.

Bir başka forum sitesinde bulduğum aşağıdaki örneği inceleyin.

Alıntı:
windowsun api settimer fonksiyonunuda kullanabiliriz.
bunu yaparken unitlerimiz içinde diğer unitlere bağımlı(classes, messages vs.)
kalmadan exeyi şişirmeden bu leziz uygulamayı inceleyebilirsiniz..
PHP Kodu:
Main.DPR

Program Main
;

uses
  Windows
ExTimer//, Dialogs;

type
  TMain 
= class(TObject)
  
Procedure OnTimer;
  private
  protected
  public
  
end;

Var
AMain:TMain;
MyTimer:TExTimer;


Procedure TMain.OnTimer;
Begin
MyTimer
.Enabled:=False;

//  ShowMEssage('dasda');

MyTimer.Enabled:=True;
End;


begin
AMain
:=TMain.Create;

MyTimer:=TExTimer.Create;
MyTimer.Interval:=1;
MyTimer.Enabled:=True;
MyTimer.OnTimer:=AMain.OnTimer;
Repeat
  MyTimer
.ProcessMessages;
  
Sleep(1);

Until (1=0);
MyTimer.Destroy;

AMain.Destroy;
end.

---------------------------------------------------------------


ExTimer.Pas
-----------

unit ExTimer;

interface

uses Windows;

type
  PMessage 
= ^TMessage;
  
TMessage packed record
    Msg
Cardinal;
    case 
Integer of
      0
: (
        
WParamLongint;
        
LParamLongint;
        
ResultLongint);
      
1: (
        
WParamLoWord;
        
WParamHiWord;
        
LParamLoWord;
        
LParamHiWord;
        
ResultLoWord;
        
ResultHiWord);
  
end;

Type
  TNotifyEvent 
procedure of object;
  
TExTimer = class(TObject)
  private
    
FIntervalCardinal;
    
FWindowHandleHWND;
    
FOnTimerTNotifyEvent;
    
FEnabledBoolean;
    function 
ProcessMessage(var MsgTMsg): Boolean;
    
procedure UpdateTimer;
    
procedure SetEnabled(ValueBoolean);
    
procedure SetInterval(ValueCardinal);
    
procedure SetOnTimer(ValueTNotifyEvent);
    
procedure WndProc(var MsgTMessage);
  protected
    
procedure Timerdynamic;
  public
    
constructor Create;
    
destructor Destroyoverride;
  
published
    procedure ProcessMessages
;
    
property EnabledBoolean read FEnabled write SetEnabled default True;
    
property IntervalCardinal read FInterval write SetInterval default 1000;
    
property OnTimerTNotifyEvent read FOnTimer write SetOnTimer;
  
end;

implementation

Free an object instance }

const
  
WM_TIMER      = $0113;
  
InstanceCount 313;

type
  TWndMethod 
procedure(var MessageTMessageof object;

type
  PObjectInstance 
= ^TObjectInstance;
  
TObjectInstance packed record
    Code
Byte;
    
OffsetInteger;
    case 
Integer of
      0
: (NextPObjectInstance);
      
1: (MethodTWndMethod);
  
end;

type
  PInstanceBlock 
= ^TInstanceBlock;
  
TInstanceBlock packed record
    Next
PInstanceBlock;
    
Code: array[1..2of Byte;
    
WndProcPtrPointer;
    
Instances: array[0..InstanceCountof TObjectInstance;
  
end;

var
  
InstBlockListPInstanceBlock;
  
InstFreeListPObjectInstance;


function 
TExTimer.ProcessMessage(var MsgTMsg): Boolean;
begin
  Result 
:= False;
  if 
PeekMessage(Msg000PM_REMOVEthen
  begin
    Result 
:= True;
    if 
Msg.Message <> $0012 then
    begin
      TranslateMessage
(Msg);
      
DispatchMessage(Msg);
    
end;
  
end;
end;

procedure TExTimer.ProcessMessages;
var
  
MsgTMsg;
begin
  
while ProcessMessage(Msg) do;
end;

Allocate an object instance }

function 
CalcJmpOffset(SrcDestPointer): Longint;
begin
  Result 
:= Longint(Dest) - (Longint(Src) + 5);
end;

function 
StdWndProc(WindowHWNDMessageWParamLongint;
  
LParamLongint): Longintstdcallassembler;
asm
        
XOR     EAX,EAX
        PUSH    EAX
        PUSH    LParam
        PUSH    WParam
        PUSH    Message
        MOV     EDX
,ESP
        MOV     EAX
,[ECX].Longint[4]
        
CALL    [ECX].Pointer
        ADD     ESP
,12
        POP     EAX
end
;


function 
MakeObjectInstance(MethodTWndMethod): Pointer;
const
  
BlockCode: array[1..2of Byte = (
    $
59,       { POP ECX }
    
$E9);      { JMP StdWndProc }
  
PageSize 4096;
var
  
BlockPInstanceBlock;
  
InstancePObjectInstance;
begin
  
if InstFreeList nil then
  begin
    Block 
:= VirtualAlloc(nilPageSizeMEM_COMMITPAGE_EXECUTE_READWRITE);
    
Block^.Next := InstBlockList;
    
Move(BlockCodeBlock^.CodeSizeOf(BlockCode));
    
Block^.WndProcPtr := Pointer(CalcJmpOffset(@Block^.Code[2], @StdWndProc));
    
Instance := @Block^.Instances;
    
repeat
      Instance
^.Code := $E8;  { CALL NEAR PTR Offset }
      
Instance^.Offset := CalcJmpOffset(Instance, @Block^.Code);
      
Instance^.Next := InstFreeList;
      
InstFreeList := Instance;
      
Inc(Longint(Instance), SizeOf(TObjectInstance));
    
until Longint(Instance) - Longint(Block) >= SizeOf(TInstanceBlock);
    
InstBlockList := Block;
  
end;
  
Result := InstFreeList;
  
Instance := InstFreeList;
  
InstFreeList := Instance^.Next;
  
Instance^.Method := Method;
end;

Free an object instance }

procedure FreeObjectInstance(ObjectInstancePointer);
begin
  
if ObjectInstance <> nil then
  begin
    PObjectInstance
(ObjectInstance)^.Next := InstFreeList;
    
InstFreeList := ObjectInstance;
  
end;
end;

var
  
UtilWindowClassTWndClass = (
    
style0;
    
lpfnWndProc: @DefWindowProc;
    
cbClsExtra0;
    
cbWndExtra0;
    
hInstance0;
    
hIcon0;
    
hCursor0;
    
hbrBackground0;
    
lpszMenuNamenil;
    
lpszClassName'TPUtilWindow');

function 
AllocateHWnd(MethodTWndMethod): HWND;
var
  
TempClassTWndClass;
  
ClassRegisteredBoolean;
begin
  UtilWindowClass
.hInstance := HInstance;
{
$IFDEF PIC}
  
UtilWindowClass.lpfnWndProc := @DefWindowProc;
{
$ENDIF}
  
ClassRegistered := GetClassInfo(HInstanceUtilWindowClass.lpszClassName,
    
TempClass);
  if 
not ClassRegistered or (TempClass.lpfnWndProc <> @DefWindowProcthen
  begin
    
if ClassRegistered then
      Windows
.UnregisterClass(UtilWindowClass.lpszClassNameHInstance);
    
Windows.RegisterClass(UtilWindowClass);
  
end;
  
Result := CreateWindowEx(WS_EX_TOOLWINDOWUtilWindowClass.lpszClassName,
    
''WS_POPUP {!0}, 000000HInstancenil);
  if 
Assigned(Methodthen
    SetWindowLong
(ResultGWL_WNDPROCLongint(MakeObjectInstance(Method)));
end;

procedure DeallocateHWnd(WndHWND);
var
  
InstancePointer;
begin
  Instance 
:= Pointer(GetWindowLong(WndGWL_WNDPROC));
  
DestroyWindow(Wnd);
  if 
Instance <> @DefWindowProc then FreeObjectInstance(Instance);
end;


TExTimer }

Procedure Exception;
Begin

End
;

constructor TExTimer.Create;
begin
  inherited Create
;
  
FEnabled := True;
  
FInterval := 1000;
  
FWindowHandle := AllocateHWnd(WndProc);
end;

destructor TExTimer.Destroy;
begin
  FEnabled 
:= False;
  
UpdateTimer;
  
DeallocateHWnd(FWindowHandle);
  
inherited Destroy;
end;

procedure TExTimer.WndProc(var MsgTMessage);
begin
  with Msg 
do
    if 
Msg WM_TIMER then
      
try
        
Timer;
      
except
       Exception
;
      
end
    
else
      
Result := DefWindowProc(FWindowHandleMsgwParamlParam);
end;

procedure TExTimer.UpdateTimer;
begin
  KillTimer
(FWindowHandle1);
  if (
FInterval <> 0) and FEnabled and Assigned(FOnTimerthen
    
if SeTTimer(FWindowHandle1FIntervalnil) = 0 then
    Begin
     Exception
;
    
End;
end;

procedure TExTimer.SetEnabled(ValueBoolean);
begin
  
if Value <> FEnabled then
  begin
    FEnabled 
:= Value;
    
UpdateTimer;
  
end;
end;

procedure TExTimer.SetInterval(ValueCardinal);
begin
  
if Value <> FInterval then
  begin
    FInterval 
:= Value;
    
UpdateTimer;
  
end;
end;

procedure TExTimer.SetOnTimer(ValueTNotifyEvent);
begin
  FOnTimer 
:= Value;
  
UpdateTimer;
end;

procedure TExTimer.Timer;
begin
  
if Assigned(FOnTimerthen FOnTimer;
end;

end
__________________
Haberbox | Tek Sevgi | Genel Seçimler | Magice Book | Yerel Seçimler
Yaşamaya Değer Bir Hayattan, Sevmeye Değer Bir Aşktan, Dostluğa Değer Bir Arkadaşlıktan Asla Vazgeçmeyin...
cemaliozan hatta değil   Alıntı Yaparak Yanıtla
Eski 09/05/2008, 00:18   #3 (permalink)
Üye
 
civil Adlı Üyenin Profil Grafiği
 
Üyelik Tarihi: 04/2007
Mesaj: 461
Varsayılan

teşekkür ederim inceliyorum ...
__________________
Yorum Yapmak Olayları Sadece Kenardan İzleyenlerin Lüksüdür
civil hatta değil   Alıntı Yaparak Yanıtla
Cevapla

Bookmarks

Seçenekler

Mesaj Yazma Hakları
Yeni mesajgöndermezsiniz
Cevap yazamazsınız
Dosya ekleyemezsiniz
Mesajınızı düzenleyemezsiniz

BB code is Açık
[IMG] kodu Açık
HTML kodu Kapalı
Trackbacks are Açık
Pingbacks are Açık
Refbacks are Açık

Benzer Konular
Konu Konuyu açana göre Forum Cevap En Son Mesaj
c# ve timer DotNetKid C# 2 24/03/2006 09:29
c++'ta timer nailgg C / C++ 5 15/03/2006 14:18
jsp de timer Jehovah Java / JSP 3 27/12/2005 09:31
timer... SineK C# 0 08/11/2005 23:17
Web App de Timer ?? Akın Öcal Javascript / DHTML / Ajax 0 02/10/2005 15:29


Forum saati Türkiye saatine göredir. GMT +3. Şu anda saat 12:00.

Reklamlar & Desteklenenler
Hassas Valf | Hassas Kaplama | Antalyamız | Gazete | Ticari Bilişim | Hakan Müştak | Rüya Tabirleri | Kadın | Hastalıklar | Cepte msn ve e-posta | Webmaster | Antalya Aupair | Turkish Property Antalya | Forum | Chat | Perde | Adsl | Araba | bolindir.com | guncelle.com | livescore | Web Tasarım | evden eve nakliyat | forum | evden eve | sohbet | Resimcim| Kalifiye İnsan Kaynakları | Web Tasarım | Oyun | Yusuf KOÇ | Akın Yorulmaz | şiir | UFO | Web Tasarım | Oyunlar | Canlı Tv |


Forum Yazılımı: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright ©2001 - 2008, Ceviz.net