Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set timer to pause

Tags:

timer

delphi

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!

like image 779
kseen Avatar asked Dec 12 '11 19:12

kseen


People also ask

Did they remove Google timer?

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.

How do I make Google stop playing music with a timer?

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.

Can you put YouTube on a timer?

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.


3 Answers

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

like image 80
relativ Avatar answered Oct 11 '22 00:10

relativ


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.

like image 9
David Heffernan Avatar answered Oct 11 '22 01:10

David Heffernan


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.

like image 2
Rob Kennedy Avatar answered Oct 10 '22 23:10

Rob Kennedy