1 procedure delay(msecs: integer); 2 var 3 Tick: DWord; 4 Event: THandle; 5 begin 6 Event := CreateEvent(nil, False, False, nil); 7 try 8 Tick := GetTickCount + DWord(msecs); 9 while (msecs > 0) and (MsgWaitForMultipleObjects(1, Event, False, msecs, QS_ALLINPUT) <> WAIT_TIMEOUT) 10 do 11 begin 12 Application.ProcessMessages; 13 msecs := Tick - GetTickcount; 14 end; 15 finally 16 CloseHandle(Event); 17 end; 18 end; 19 20