从国外网站上找的,编译出来的程序有点大,还有更好的方法。
program Project2; {$APPTYPE CONSOLE} uses SysUtils, ExtCtrls, Classes; type PMethodPointer = ^TMethodPointer; TMethodPointer = packed record pMethod: Pointer; pObject: TObject; end; var T : TTimer; p : TMethodPointer; i : Integer; procedure NotifyEvent(Self: TMethodPointer; Sender: TObject); begin writeln('yes'); beep; end; begin T := TTimer.Create(nil); T.Interval := 200; // -> l?st alle 200 ms das OnTimer-Event aus try p.pMethod := @NotifyEvent; p.pObject := nil; T.OnTimer := TNotifyEvent(p); T.Enabled := true; // aktiviert den Timer writeln('Warte auf Event: '); for i := 1 to 5 do begin sleep(500); writeln('warte ' + inttostr(i * 500) + 'ms...'); NotifyEvent(p, T); end; T.Enabled := false; // deaktiviert den Timer finally T.Free; end; end.
关键字词: