Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delay() in Delphi 1.0 ?

1,002 views
Skip to first unread message

Tapani Mikkilä

unread,
May 2, 1997, 3:00:00 AM5/2/97
to

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ä

Kirk B. Spadt

unread,
May 2, 1997, 3:00:00 AM5/2/97
to

In article <5kce4r$q...@idefix.eunet.fi>,

tapani....@mmr.pp.fi (Tapani Mikkilä) wrote:
>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 ????

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

Damien M

unread,
May 3, 1997, 3:00:00 AM5/3/97
to


> 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

JefSummers

unread,
May 5, 1997, 3:00:00 AM5/5/97
to

In article <01bc57b4.0f4a7940$8de91acb@none>, "Damien M"
<dam...@ansonic.com.au> writes:

>> 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


Archi...@euromail.com

unread,
May 8, 1997, 3:00:00 AM5/8/97
to

>program with "Delay(nnn)" command.
>

Just write Delay(nnn)

A.Zoettl

Bryan Valencia

unread,
May 10, 1997, 3:00:00 AM5/10/97
to Archi...@euromail.com
The problem I have with DELAY is that it TAKES OVER all windows
function. You can't Send a delay for a long period to allow another
action to complete. The user can't toggle to another app... If you
want to wait for an action to complete, use Application.ProcessMessages.
--
--------------------------------------------
In theory, theory and practice are the same.
In practice, they are not.
--------------------------------------------
Bryan Valencia
Software Services - Making Windows Scream
WWW : www.invsn.com/softserv/
email : bry...@thevision.net
--------------------------------------------


David B. Wright

unread,
Jun 1, 1997, 3:00:00 AM6/1/97
to

Kerry Sanders <cod...@mindspring.com> wrote in article
<33911a0...@news.mindspring.com>...
> On 2 May 1997 10:03:07 GMT, tapani....@mmr.pp.fi (Tapani Mikkilä)
wrote:

>
> |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 ????
>
> Just curious... why do you want to delay the execution of an event driven
> program?
>

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


David B. Wright

unread,
Jun 1, 1997, 3:00:00 AM6/1/97
to

phil...@ihug.co.nz wrote in article
<3391f24e...@newsource.ihug.co.nz>...

> >
> >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;
> >....
> >-- David
> >
>
> Dont forget Application.ProcessMessages(); in the loop.
> Not so important in 32bit, as only your process will stall, but in
> 16bit, the whole computer will freeze until the delay is up.
>
>

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


0 new messages