?
Solved

Delay with process.messages

Posted on 1998-07-02
6
Medium Priority
?
1,787 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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