DelphiFAQ Home Search:

Wait for an amount of milliseconds

 

comments2 comments. Current rating: 4 stars (1 votes). Leave comments and/ or rate it.

The Win32 API has the function Sleep(ms : longint); for this purpose.

If you are working with D1, use the following function - it waits for a given amount of milliseconds.
It allows the current application and other applications to process incoming messages:

procedure Delay(ms : longint);
var
  t1 : longint;
begin
  t1 := GetTickCount;
  while (GetTickCount - t1) < ms do
    Application.ProcessMessages;
end;

Comments:

2007-04-13, 09:42:19
anonymous from United Kingdom  
rating
While this delay works fine if its used on a computer that is rebooted regularly, the gettickcount function returns a DWORD value of number of milliseconds since windows started, so the t1 variable really should be a longword if you ever use in a program thats run on a machine that gets left on for long periods of time...

procedure Delay(ms : longint);
var
t1 : longword;
begin
t1 := GetTickCount;
while (GetTickCount - t1) < ms do
Application.ProcessMessages;
end;
2008-05-17, 05:10:20
anonymous from Iran  
I am very hard Nokar.
thanks for your guidence.

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
Leave your comment here:
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.