WarPie90

TTimer

Jun 8th, 2022 (edited)
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.61 KB | None | 0 0
  1. program new;
  2.  
  3.  
  4. procedure Test(Sender: TObject);
  5. begin
  6.   WriteLn('>>> ', GetTimeRunning());
  7. end;
  8.  
  9. procedure TTimer.Setup();
  10. begin
  11.   Self.Init(nil);
  12.   Self.SetOnTimer(@Test);
  13.   Self.SetInterval(100);
  14.   Self.SetEnabled(True);
  15. end;
  16.  
  17. procedure TTimer.__Toggle();
  18. begin
  19.   self.SetEnabled(not self.GetEnabled());
  20. end;
  21.  
  22. function TTimer.Toggle(): Boolean;
  23. begin
  24.   Sync(@Self.__Toggle);
  25.   Result := Self.GetEnabled();
  26. end;
  27.  
  28.  
  29. var
  30.   t: TTimer;
  31. begin
  32.   sync(@t.Setup);
  33.   for 0 to 10 do
  34.   begin
  35.     Sleep(500);
  36.     WriteLn t.Toggle();
  37.     Sleep(500);
  38.     WriteLn t.Toggle();
  39.   end;
  40.  
  41.   t.Free();
  42. end.
Add Comment
Please, Sign In to add comment