Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TTimer reset

Status
Not open for further replies.

mironto

Programmer
May 12, 2001
26
SK
I am planning to program autosave feature in my application and I'm planning using TTimer for saving period. Can I retrieve the time tiil OnTimer event occurs and can I reset the timer so it starts counting from beginning? (I need this because when user presses "manual" save button, I want the autosave feature reset).
 
Well, there is no API or VCL call for that, but instead, in your TTimer class add a code to accumulate the time expired and trigger the events when the time is right (if the auto-save is enabled, which can be a separate call to some method in TTimer class, like void __fastcall DisableAutosave() ). After that, you just reset you total-time counter and that's it!
 
If you want to know how many milliseconds have passed, you can call GetTickCount(). It returns an unsigned long int of the number of milliseconds passed since windows was started. You can then have a global variable "LastTimeStarted" and write to that global when the timer kicks off. Then you just subtract to get the time difference between now and when the timer kicked (GetTickCount() - LastTimeKicked). if this is greater than say 10000 ms, then your timer has elapsed 10 seconds. Of course, you can apply the same idea to whatever other need you have.

Chris
 
Thanks for your suggestions, but I found another solution. I can reset TTimer by disabling and subsequently enabling it - and that's all I need for my autosave feature. Very simple and don't know why didn't I come up with this in the first place ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top