Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi Timer: Time before next event

Tags:

timer

delphi

Is it possible to determine when a TTimer in Delphi will trigger? I know how to calculate this based upon the timer's last run and the timers interval. Unfortunately, the code I am working with has many states and the interval can change in many ways. I would prefer to not have to keep track of when the timer was last enabled and the interval changed, but instead directly access this information from the timer.

Scenario: A timer has a 2 minute interval, 30 seconds have elapsed since it was last enabled, how do I find out in code that in 90 seconds the timer event will trigger again?

Is it possible to get this information from the timer directly? Or perhaps the OS? The timer component must "know" when it will be triggered next. How does it know? Is this information I can access?

like image 866
sse Avatar asked Aug 31 '11 21:08

sse


1 Answers

There's absolutely no way to query a Windows timer for information of this nature. You will simply have to keep track of this yourself.

I would do this by wrapping up the TTimer with composition and not inheritance. You can then be sure that you will capture all modifications to the timer state.

like image 180
David Heffernan Avatar answered Oct 10 '22 02:10

David Heffernan