*snip*
And you would still need the sleep for the loop to keep the cpu from 100%.
Lets revisit my pseudo-example:
begin
start-timer-procedure-here
repeat
i:=0;
inc(i);
if-timer-intervall-passes writeln(i); (if intervall hasn''t passed wait for it)
until false;
end.
Explain your pseudo-code, please.
What I'm seeing is an endless loop (repeat/until) in which
i will be set to 1 (zero, then incremented), then probably the
if will not be satisfied. After that it will wait for interval to pass and will loop again. Then again,
i will be set to 1, it will be printed, then loop again since the interval has already passed. From that point it will endlessly print '1'. Timer was started just once before the loop.
I doubt that it is intended to print endlessly '1', so explain please.
I wouldn't say the
sleep/delay are useless, it all depends on what you want to achieve.
Generally speaking, the callback technique (event handlers) used extensively in GUI applications (also into the TFPTimer), is very convenient for interactive applications, but it is not the only way you can go to write your program. If you're not comfortable with it you can use
GetTickCount64 to do what you want . And then your code may look much more logical to you.