Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Delphi TTimer Program

can anyone help me how to display a simple timer using TTimer component in Delphi? I have a label where will the countdown from 5-0 will be displayed. Please help. Just a simple one. Thanks

like image 963
Tony Avatar asked Dec 19 '25 23:12

Tony


1 Answers

You don't say what the time interval between 5 and 0 is, but I'll assume that it's seconds. You need to define a global variable of type integer with an initial value of 5 (I'll call it 'countdown'), and a timer with an interval of 1000. Its OnTimer method will be as follows:

Procedure Timer1Timer (sender: TObject);
begin
 if countdown > 0 then
  begin
   dec (countdown);
   label1.caption:= inttostr (countdown)
  end
 else timer1.enabled:= false
end;

When you want the countdown to commence, enable the timer and set the label's caption to be '5'.

like image 85
No'am Newman Avatar answered Dec 21 '25 13:12

No'am Newman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!