Hello !
With Borland Pascal there was easy way to pause the excecution of the
program with "Delay(nnn)" command.
How to do the same in Delphi 1.0 ????
Thanx in advance
Tapani Mikkilä
A few ways I use:
1. If I do not mind using Application.ProcessMessages (if not alot of
other processes are running):
procedure Delay(Seconds: Integer);
var
StopTime: TDateTime;
begin
StopTime := Now + Seconds / 24 / 60 / 60; {TDatetime = 1.0/day}
while Now < StopTime do
Application.ProcessMessages;
end;
2. To use the Windows message loop and a timer (shares resources
better):
procedure TFormX.Proc1;
begin
{Stuff before delay}
Timer.OnTimer := TFormX.Proc2;
Timer.Interval := Seconds * 1000;
Timer.Enabled := True;
end;
procedure TFormX.Proc2(Sender: TObject);
begin
Timer.Enabled := False;
{Stuff after delay}
end;
Note that Timer is a TTimer component placed on the form FormX, with
its Enabled property set to False.
------------------------------------------------
Kirk B. Spadt ksp...@keyware.com
Keyware Systems, Inc.
570 Lindsey Drive (610) 964-9530
Radnor, PA 19087 (610) 964-0543 fax
> tapani....@mmr.pp.fi (Tapani Mikkilä) wrote in article
<5kce4r$q...@idefix.eunet.fi>...
>
> Hello !
>
> With Borland Pascal there was easy way to pause the excecution of the
> program with "Delay(nnn)" command.
>
> How to do the same in Delphi 1.0 ????
>
> Thanx in advance
>
>
> Tapani Mikkilä
>
yeah there's a:
sleep(milliseconds);
in kernel.dll
It halts the code in VB, I suppose it should do the same in delphi.
look it up in the windows api help file.
regards,
Kinetic
>> With Borland Pascal there was easy way to pause the excecution of the
>> program with "Delay(nnn)" command.
>>
>> How to do the same in Delphi 1.0 ????
>>
Best way I have seen:
procedure Sleep(millisec : Integer);
var
theTime : LongInt;
begin
theTime := GetTickCount{verify this syntax};
while GetTickCount<theTime+millisec do application.ProcessMessages;
end;
/js
>program with "Delay(nnn)" command.
>
Just write Delay(nnn)
A.Zoettl
Yes, I know this is unusual, but I've come across this myself as well.
Here's a routine that should delay for AT LEAST n ms (though it could delay
for slightly longer as well):
procedure Delay(n : longint);
var
StartTime : Longint;
begin
StartTime := GetTickCount;
while ((GetTickCount - StartTime) < n) do ;
end;
The key here is GetTickCount, which in a prime example of truth in
advertising will actually return the number of milliseconds elapsed since
Windows was started. I believe this number does roll over somewhere around
49 days, so it might not be appropriate for 24/7 dedicated apps, but for
most user apps this'll be fine.
Enjoy, but be careful ...
-- David
Putting Application.ProcessMessages in the loop *does* allow other tasks to
run--including other events within your own application, such as menu
selections, buttons, etc (and, incidentally, the possibility of re-entering
the code which caused the delay in the first place). I take it from the
original request that the intent was to essentially "shut down" the whole
program for a certain time, not just a particular procedure.
You do make a good point, however -- Windows development requires an
awareness that your app may not be (actually, will never be) the ONLY app
running on a system -- you gotta play nice, or the user won't play with you
at all ...
-- David