GetTickCount has been deprecated in favor of GetTickCount64, which gives a qword result and so it "solves" the wrap-arount to 0 of the tick after 49.7 days, so one doesn't have to worry that the expression

   GetTickCount64-PreviousTick

will ever give a negative result, and

  if GetTickCount64-PreviousTick>WaitTime then


is guaranteed to work for the next ~500 millions years.

However GetTickCount64 isn't available in windows XP, so the rtl simulates it by using.....GetTickCount, with the result that the above "if" condition could fail after 49.7 days. For that I still have to use DWORDs instead of qwords and cast the subtraction to DWORD (so that the rollback doesn't matter as long as the WaitTime above is less than $ffffffff)

BEFORE (with gettickcount):

----------------------------------------------------------------------
var PreviousTick:DWORD;

...
  PreviousTick:=GetTickCount;
...
... if DWORD(GetTickCount-PreviousTick)>WaitTime then....
----------------------------------------------------------------------


NOW (with gettickcount64)

----------------------------------------------------------------------
var PreviousTick:QWORD;
...
  PreviousTick:=GetTickCount64;
...
... if GetTickCount64-PreviousTick>WaitTime then....
----------------------------------------------------------------------


Which seems cleaner but isn't really guaranteed to work, so I have to:

----------------------------------------------------------------------
var PreviousTick:DWORD;
...
  PreviousTick:=DWORD(GetTickCount64);
...
... if DWORD(DWORD(GetTickCount64)-PreviousTick)>WaitTime then....
----------------------------------------------------------------------


wouldn't have been better to just leave GetTickCount alone, without deprecation (and maybe give a warning that GetTickCount64 doesn't give a usable result on all platforms)?


Bye
--
Luca
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to