Delay Function in Delphi

Is there a function available just like the Sleep(..) in C?
Besides Timer can we write a function to delay acurrately time?
ysimonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
Use sleep!

Cheers,

Raymond.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
philipleighsCommented:
ie. Sleep is a Win32 API function, not a C language function.
0
hagurCommented:
Hello,

Use this procedure, it works just like the delay function in Pascal.

procedure TForm1.Delay(msecs:integer);
var
   FirstTickCount:longint;
begin
     FirstTickCount:=GetTickCount;
     repeat    
           Application.ProcessMessages; {allowing access to other
                                         controls, etc.}
     until ((GetTickCount-FirstTickCount) >= Longint(msecs));
end;
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

drajaytandonCommented:
Note:

Becareful using the application.processmessages solution, as although it works, it uses 100% CPU load.
0
StuartB_99Commented:
You can use Sleep(), as it is in the Windows API, to use it you must include Windows to your uses clause then just simply type Sleep(n);

procedure Sleep; external kernel32 name 'Sleep';

procedure Sleep(dwMilliseconds: DWORD); stdcall;

eg

Procedure TForm1.WaitFor(Seconds : Integer);
Begin
 Sleep(Seconds);
End;
0
stevenvhCommented:
I don't agree with drajaytandon's remark about application.processmessages using 100% CPU time. This method lets Windoze check the message loop for waiting messages from other apps. In fact if you perform actions which take a long time to finish, and you don't execute application.processmessages from time to time, other apps may appear to be frozen, notwithstanding Microcrap's claims about preemptive multitasking.
0
drajaytandonCommented:
Stevenvh's comment is true, we need to use Application.processmessages to allow the message queue to be processed but in NT you see that 100% CPU load is being used.

I have heard a combination of Application.ProcessMessages and Sleep (1) should be used, with Sleep (1) being used sparingly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.