[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1803
  • Last Modified:

Delay with process.messages

I want to include a delay in my Delphi (3) program. I wan't to do this with a variable and a timer: I activate the timer,  and the the timer set this variable to true. during this time I ask if this variable is true, but the programm is busy only with this repeat routine. I want to use process.messages...... but I don't know how to include this in my programm. Can anyone make me a little exampleprogram???
Thank you!
0
zulliger
Asked:
zulliger
1 Solution
 
ronit051397Commented:
You need to write something like:
while ... do
  Application.ProcessMessages;
0
 
ZifNabCommented:
It is like Ronit says, you've to include in your loop the Application.ProcessMessages.

But way don't you just use a delay function, instead of the timer?

Zif.
0
 
ZifNabCommented:
Here are some delay procedures :

    How do you get your Delphi app to do nothing for a period of time?
    A:
    Uses
         ....
         Winprocs
         ....;

    Procedure delay(millisecs : longint);   { delay for given milliseconds }
    var
         endtime   : longint;
    begin
         endtime := gettickcount + millisecs;
         while endtime - gettickcount < 0 do
              Application.ProcessMessages;
         end; { delay }

    A:
    procedure Wait;
    var oldTime: LongInt;
    begin
      oldTime := GetCurrentTime;
      repeat
       { whatever}
      until GetCurrentTime - oldTime >= yourDelay;
    end;

    To which I would add:

    As current Windows does not have pre-emptive multi-tasking,
    it's normally good event-handling manners to allow Windows
    to jump in to the gap, so the { whatever } above should
    usually read:

              Application.ProcessMessages;


    A:
    Procedure Delay(DTime : LongInt);
    Var
      L : LongInt;
    Begin
      L := GetTickCount;
      While (Abs(L-GetTickCount) < DTime) do;
    End;

    The usage is "Delay(1000'th of a second)", for example
    Delay(5000) will wait 5 seconds.

Regards, Zif.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GreedyCommented:
have you noticed that this delay function kinda beets on the processor...was that why you have a timer?  so you can check it under a bigger cycle like every second look if you are still in the wait mode?...The RxLibraries have a neet little component called a RxClock that has an OnAlarm Event just set the AlarmHour, AlarmMinute, and AlarmSecond and it goes off at the second...with almost no system load I would say none but it does have to execute a few instructions a second... look around for RxLib 2.4 if you can't find it I can send it to you...the component is a visual clock thing but you could just snag out the code for defining the OnAlarm event to suit your needs.  take a look at
http://rx.demo.ru/
http://www.officeauto.com/res/rx/


0
 
zulligerAuthor Commented:
Thank you for your answers!
0
 
bengoreCommented:
You can use the API function: Sleep() or SleepEx() from the unit windows.

The Sleep function suspends the execution of the current thread for a specified interval.
function Sleep(  
cMilliseconds       // sleep time in milliseconds
   );      
Parameters

cMilliseconds

Specifies the time, in milliseconds, for which to suspend execution. A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. A value of INFINITE causes an infinite delay.

Return Value

This function does not return a value.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now