AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Timer ohne Formular

Ein Thema von meisteralex · begonnen am 25. Nov 2005 · letzter Beitrag vom 27. Nov 2005
 
Benutzerbild von sniper_w
sniper_w

Registriert seit: 11. Dez 2004
Ort: Wien, Österriech
893 Beiträge
 
Delphi 6 Enterprise
 
#4

Re: Timer ohne Formular

  Alt 27. Nov 2005, 00:13
Auszug aus BallonKiller:
Delphi-Quellcode:
type
  TActorEvent = procedure (Sender:TObject) of object;

  TMyTimer = class
    private
      FOnTimer:TActorEvent;
      FInterval:Cardinal;
      FHandle:Cardinal;
      FOwner:Cardinal;
    protected
      procedure SetInterval(Value:Cardinal);
    public
      constructor Create(AOwner:Cardinal);
      procedure AfterConstruction();override;
      procedure BeforeDestruction();override;
      procedure DoTimerProc();
    published
      property OnTimer:TActorEvent read FOnTimer write FOnTimer;
      property Interval:Cardinal read FInterval write SetInterval;
  end;

[...]
procedure TimerCallBack( Hwnd_ : HWND;   // handle of window for timer messages
                        uMsg :UINT;   // WM_TIMER message
                        idEvent :UINT;   // timer identifier
                        dwTime :DWORD    // current system time
                        );stdcall;
  var CallingTimer:TMyTimer;
begin
  CallingTimer := TMyTimer(idEvent);
  CallingTimer.DoTimerProc();
end;

{ TMyTimer }

procedure TMyTimer.AfterConstruction();
begin
  inherited;
  FInterval := 1000;
  FHandle := SetTimer(FOwner, Cardinal(Self), FInterval,@TimerCallBack);
end;

procedure TMyTimer.BeforeDestruction();
begin
  inherited;
  KillTimer(FOwner,Cardinal(Self));
end;

constructor TMyTimer.Create(AOwner: Cardinal);
begin
  FOwner := AOwner;
end;

procedure TMyTimer.DoTimerProc();
begin
  if Assigned(FOnTimer) then
    FOnTimer(Self);
end;

procedure TMyTimer.SetInterval(Value: Cardinal);
begin
  if FInterval <> Value then
  begin
    FInterval := Value;
    KillTimer(FOwner,Cardinal(Self));
    FHandle := SetTimer(FOwner, Cardinal(Self), FInterval,@TimerCallBack);
  end;
end;
Hier :constructor TMyTimer.Create(AOwner: Cardinal); Wenn du kein Fenster hast, kann auch 0 übergeben werden. ( glaube ich )
Katura Haris
Es (ein gutes Wort) ist wie ein guter Baum, dessen Wurzel fest ist und dessen Zweige in den Himmel reichen.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:13 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz