Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delay with process.messages

Posted on 1998-07-02
6
Medium Priority
?
1,794 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

636 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