Solved

Delay with process.messages

Posted on 1998-07-02
6
1,755 Views
Last Modified: 2008-02-01
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
Comment
Question by:zulliger
6 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356979
You need to write something like:
while ... do
  Application.ProcessMessages;
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1356980
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1356981
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Expert Comment

by:Greedy
ID: 1356982
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
 

Author Comment

by:zulliger
ID: 1356983
Thank you for your answers!
0
 

Accepted Solution

by:
bengore earned 50 total points
ID: 1356984
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question