3

Possible Duplicate:
Delphi Timer: Time before next event

Using C++ builder XE on Windows 7 Pro (64 bit) :

I have a TTimer on a form.

What I want to do is to update a progress bar to show how long the TTimer has left before it calls the OnTimer event handler.

Is there any way to find out low long it will be until the TTimer's interval fires the OnTimer event ?

Community
  • 1
  • 1
Nigel Stevens
  • 147
  • 1
  • 1
  • 9
  • And this: [How to get timeleft in Timer?](http://stackoverflow.com/q/8763976/576719) was an exact duplicate of the above question. – LU RD Jan 22 '13 at 18:26

1 Answers1

3

No, Windows timers provide no interface for that.

Since you're going to be updating a progress bar anyway, you'll already have some periodic code that's running more frequently than the timer that you want to track. That code will be triggered by a timer, so in that timer code, check the current time and compare out to the due time you previously calculated for the timer you wanted to track.

Then, get rid of the first timer since you no longer need it. Instead, just use the "tracking" timer to trigger the original code when it's time. Ultimately, you'll have one timer that continuously checks whether it's time to run the code. If it's time, then run the code; otherwise, update the progress bar instead.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • What about adding a setter to TTimer.Enabled property to set the current timestamp, and then expose a new property named "remaining" or something like that? – Leonardo Herrera Jan 22 '13 at 18:19
  • That would be "the due time you previously calculated for the timer," @Leonardo. Whether you put the calculation in the component out outside, it doesn't change the answer to the question. The OS and the library provide no support, so you have to implement it separately. – Rob Kennedy Jan 22 '13 at 18:32
  • The question is whether it is possible to do this on a `TTimer`. You have the moment the timer was enabled, and you have the `Interval` property. Just making sure of disabling the timer inside its `OnExecute` method should be enough to have a good-for-display estimate. In any case, LU RD points to a duplicated question that discusses a lot about this (including some similar answers and warnings about this not being terribly accurate.) So this looks like a duplicate in any case :-) – Leonardo Herrera Jan 22 '13 at 18:44