Enable and disable Ttimer

Asked

Viewed 1,092 times

2

How to enable and disable TTimer? I have a procedure:

procedure TForm3.Timer1Timer(Sender: TObject);

When I click on a download button, enable the Timer:

Timer1.enabled := true;

And when I click cancel it should stop the Timer:

Timer1.enabled := False;

But that’s not what happens. The Timer continues and keeps processing the data and displaying in a Label... for me to stop the Timer once I have to use:

Timer1.OnTimer :=  nil;

What is the correct way to enable and disable this timer, for in the Procedure TForm3.Timer1Timer( has some commands, and even I give Timer1.enabled := False; on the cancel button it continues processing and showing on the screen.

What is the right way to use the timer in such a situation, enable and disable?

1 answer

0


To disable the timer just type:

Timer1.enabled := False;

And to enable:

Timer1.enabled := True;

You must be disabling the timer in the wrong place.

  • Really... I was disabling it in the wrong location... I was inside a Try ... But I do not know if it is wrong, I went and put a global variable, where I received a boolean value... then I check inside the timer if it is true or False... worked super well... then I do not need to disable the timer... I don’t know if it’s an advantage... but this way I only use a timer with several different commands... because at no time it will be disabled...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.