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!
You cannot do that with a
TTimerwhich is a loose wrapper around theSetTimerAPI.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
Enabledproperty toFalseand 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
TTimeris not the best fit for your problem. But, having said that it would not be terribly difficult, and quite fun, to produce aTTimervariant that supported pausing the way you desire.