Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17



Posted on 1998-10-24
Medium Priority
Last Modified: 2010-04-06
I have many looping process,, and repeat..until. I should add Application.ProcessMessage inside the looping process.
When I should using Application.ProcessMessage ?

Question by:joely
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
  • 3
  • 2
  • 2
  • +2

Expert Comment

ID: 1344195
i think you should you Application.ProcessMessages whenever you have loops,because its give a chance to your application to process other messages in the queue.

LVL 17

Expert Comment

ID: 1344196
hello Joely
i agree entirely you should always use ProcessMessages while a loop is going on .Without it you have no way to interact with your app or even close it.Even system messages etc will be
queued until the loop stops.
 ¤¤¤¤¤¤¤ InThe ¤¤¤¤¤¤¤


Accepted Solution

tleforge earned 40 total points
ID: 1344197
It depends.

If you have ANY threading or background processing going on DO NOT use application.processmessages.  This would defeat their whole purpose.

If you are trying to make sure that a component updates visually then call the refresh method for that component (ie: label1.refresh)

Use of processmessages should be as infrequent as possible.  If you find that the interface is being locked up too often by resource hogging processes, you may want to look into using threads for those processes.

Only use processmessages if you must be certain that all processes be completed at a certain time.

For an example of how much it can slow down an application, put a label and button on a form.  In the click event of the button place the following code:

       iLoopVar1, iLoopVar2: integer;
       for iLoopVar1 := 0 to 100 do
         for iLoopVar2 := 0 to 1000000000 do begin
            Label1.Caption := IntToStr(iLoopVar1);
            // Label1.Refresh;
         end; {iLoopVar2}
     end; {click event}

Sit back and time this, then uncomment the Label1.Refresh line and comment the Application.ProcessMessages line and time it again.

I know you're not going to be doing loops like this all the time, but...

Hope this helps.
Technology Partners: 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!

LVL 10

Expert Comment

ID: 1344198
All od the guys are right, but I suggest you don't try tleforge's example since you'd have to reset the program....

btw- Barry... PLease tell me how to make those stars..

LVL 17

Expert Comment

ID: 1344199
yo hello viktor

it's how i told you before but your keyboard layout is probably
english(us) whereas mine is english(uk)no hangon that work's too um...
goto control panel;
either select or add english(united states);
set that as default;
then under properties select united states 101;
apply , ok;

then you should be able to hold down alt and press 4111
release alt and anyway it work's for me were using the keypad were'nt you with the numlock on?
                  <¤   ¤
later dude Barry  <¤   ¤  
                      ¤   ps.floppy's in the post.
LVL 10

Expert Comment

ID: 1344200
I've got U...S.... 101 ...Don't know why it doesn't work.... s***

btw- 10x for the floppy...

P.S. I didn't use NumLock on neither the Caps Lock on... Any other ideas??


Author Comment

ID: 1344201
Based on your example that you given me, you put Application.ProcessMessages just in second loop and you not put it in first loop. Why ?
How if I have loop more than two, I just put it in last loop.

Expert Comment

ID: 1344202
Actually, as someone pointed out before, this will make your app hang for quite a while.  You may want to put the processmessages in the outer loop instead.  This will still give you a good feel for the timing involved and that's ALL that example was meant to do.

As for 'where' processmessages should go, follow these three rules and you should do well:

  1.  Always try to do without processmessages.
  2.  If possible, where you REALLY NEED for the user to have
      control (as opposed to the application) try to use threads.
  3.  If threads are not possible THEN AND ONLY THEN use

To answer your question... if it comes down to number 3, use processmessages in WHATEVER loop gives control back to your users without significantly slowing down your application.  There is no 'rule' pertaining to whether processmessages should go in an inner or outer loop.  The best I can do is to tell you to TRY putting it in the loop that iterates fewer times (even though I didn't do that in my example... another bad case of 'do as I say, not as I do;-)

I hope that clarifies things a little more.  If you need anymore help, please feel free to email me at

Expert Comment

ID: 1344203
Just to give you a little background on where I'm coming from...

I'm a clock-cycle counter... if I can find ANY way to make my programs run faster (without negatively impacting the GUI, of course), I'll use it.  I like to tweak the code as much as possible.  Sometimes I drive my employers nuts because they want the product out the door and I'm still tweaking away trying to shave a half second of a particular process.

I have had to, from time to time (and though it went against every fiber of my being), just get the application finished to please the powers-that-be.  And THEN I go back and tweak;-)

I've said all this to say that, if you need to get a project done and using processmessages doesn't slow the app down too much then, by all means, use it.  HOPEFULLY, you can go back and tweak for the next version.  My experience has been otherwise.

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…
Suggested Courses

660 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