Mirror

How to check the timer progress (Views: 14)


Problem/Question/Abstract:

I have a TTimer that is programmed to show a message box after 5 minutes. Is there a way to check how much of the timer interval has passed after a certain time?

Answer:

You will have to use a timer that occurs every second and increments a variable (even its own Tag property).

TForm1.Timer1Timer(Sender: ...);
begin
  Timer1.tag := Timer1.tag + 1;
  if Timer1.tag = 300 then
  begin
    Timer1.enabled := false;
    {If you leave, it will show a message every 5 minutes, resulting in many windows;
    suspend counting for the period showing the message}
    Timer1.tag := 0;
    showmessage('5 Minutes!!!');
    Timer1.enabled := true;
  end;
end;

TForm1.button1click(....);
begin
  showmessage('Only ' + inttostr(Timer1.tag div 60) + ' minutes and ' +
    inttostr(Timer1.tag mod 60) + ' seconds have passed');
end;

<< Back to main page