Implementation of Delay procedure

Do you remember Delay procedure from Turbo (Borland) Pascal? It was used to pause the program “flow” for specific time interval. In Windows, there is a different style of programming, but sometimes (maybe) the Dealy procedure may be useful. Here is a simple implementation of Delay procedure using Delphi.

There are more ways to “simulate” Delay, but this one is really simple and “nonblocking”. It means, that it pauses the application, but not whole system.

procedure Delay(ms: integer);
var now: integer;
begin
  now := GetTickCount + ms;
  while GetTickCount < now do Application.ProcessMessages;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Delay(10000);
  ShowMessage('Finished');
end;

Leave a Reply