Mega Code Archive

 
Categories / Delphi / Examples
 

Sleep without hanging

This demo shows how to use the THPCounter-component in a routine that performs a sleep without stopping program-execution. Application.ProcessMessages permits Windows to process the messages that are in the message queue, and therefore makes the application "alive" in a way that an ordinary sleep-command wouldn't do. procedure TForm1.Wait(MSec: integer); begin Caption:= 'Start'; HPCounter1.Start; repeat Application.ProcessMessages; until HpCounter1.ReadInt >= MSec * 1000; Caption:= 'Ready'; end;