Link to home
Start Free TrialLog in
Avatar of siwiher
siwiher

asked on

Accurate Timer

Hi there, I'm making a stopwatch program and i've hit a glitch.

I thought evreything was working perfectly until I compared a minute on my program and a minute on the computer's clock.

The two times were 3 seconds apart.

I am using the Ttimer component to count out 100 miliseconds to the second and 60 seconds to the minute.

Please help, Siwiher!
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

you could use TJvThreadTimer that is a replacement for the TTimer component, with a better accuracy (1 millisecond)
it's a component of the JVCL library
get it at http://homepages.borland.com/jedi/jvcl/

You should not count events.

StartTime := GetTickCount;

or better (higher resolution)

QueryPerformanceCounter(StartTime)

and then

CurrentTime := GetTickCont;
TimeElapsed := CurrentTime-StartTime;


QueryPerformanceCounter(CurrentTime)
QueryPerformanceFrequency(Freq)
TimeElapsed := (1000*(CurrentTime-StartTime)) div Freq;
Avatar of siwiher
siwiher

ASKER

mokule >>

please could i have have a workin example - the code above looks like latin to me!
ASKER CERTIFIED SOLUTION
Avatar of mokule
mokule
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of siwiher

ASKER

Brilliant Mokule thanks very much!