How can I pause TTimer
in Delphi with keeping interval? So, for instance, I have TTimer
that has 10 seconds interval and when I set timer to pause after first 7 seconds of working, it will save its state, and then when I resume timer it will fire after remaining 3 seconds.
Thanks a lot guys!
The feature is still missing today. It turns out that Google hasn't decided to remove the handy feature without warning. In a tweet, the company's public search liaison Danny Sullivan confirmed that the feature is temporarily unavailable because of an unspecified problem.
Note: You can turn off a timer or an alarm without saying, “Hey Google.” Just say, “Stop.” This feature is available on Google Nest and Home speakers and displays in English-speaking countries.
Tap the Lock in the bottom corner of any page in the app. Read and enter the numbers that appear or enter your custom passcode. Select Timer . Use the slider bar or the and icons to set a time limit.
Timer.interval :=1000;
ICount:integer;
In create procedure set icount to 0
Procedure timerevent(sender:tobject);
Begin
If icount=10 then
Begin
// do proccess
Icount = 0;
End;
Inc(icount);
End;
Now you can stop the timer anywhere
You cannot do that with a TTimer
which is a loose wrapper around the SetTimer
API.
In order to do this you would need to keep track of when the timer started and when you paused it. Then you would know how much time was left. When you need to pause, set the timer Enabled
property to False
and set the interval to be the amount of time remaining. Don't forget that after the timer fires for the first time you need to reset its interval to the true interval.
As you can see from the above, a TTimer
is not the best fit for your problem. But, having said that it would not be terribly difficult, and quite fun, to produce a TTimer
variant that supported pausing the way you desire.
That's not how the Windows timer facility works, and that's not how the Delphi wrapper works, either.
When you disable the timer, keep note of how much time was remaining before it was due to fire again. Before you re-enable it, set the Interval
property to that value. The next time the timer fires, reset Interval
to the original value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With