Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

TTimer

English · Français · Suomi · Русский

TTimer is component on the System tab of the Component Palette and delivers a timer with usually millisecond resolution. It inherits most of its properties from TCustomTimer. It is defined in the ExtCtrls unit.

Countdown calculation example

pascal
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Label1.Caption := Format('%d sec',[start]);
  Dec(start);
  if (start < 5) then Shape1.Brush.Color:=clYellow;
  if (start < 0) then begin
    Timer1.Enabled := False;
    Shape1.Brush.Color:=clGreen;
    Label1.Caption := 'Finished!';
  end;
end;
pascal

procedure TForm1.FormCreate(Sender: TObject);
begin
  Caption := 'Countdown calculation';
  Timer1.Interval := 1000;
  Timer1.Enabled := True;
  Label1.Caption := '';
  Shape1.Shape := stCircle;
  Shape1.Brush.Color:=clRed;
  start := 20;
end;

Notes

pascal
  Timer1.Enabled := False;
  Timer1.Enabled := True;

Each time the code is executed the timer shall start counting from the beginning without the OnTimer event being triggered.

See also


From the Free Pascal wiki, page "TTimer", as it stood on 2023-01-10 after a change by Dirkjvanderveen, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .