Solved

Delay with process.messages

Posted on 1998-07-02
6
1,742 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
Comment Utility
You need to write something like:
while ... do
  Application.ProcessMessages;
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:Greedy
Comment Utility
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
Comment Utility
Thank you for your answers!
0
 

Accepted Solution

by:
bengore earned 50 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now