when 2 use Application.ProcessMessages;

How do I know that a message is waiting and critical if I donot use Application.ProcessMessages;

And how do I know there is no message in que and no need to use Application.ProcessMessages;

In short is there a property/condition that fits here:

repeat
  Application.ProcessMessages;
  until XXXXXX

Thx
GurkanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheNeilCommented:
You should never have to do this. If you're trying to monitor Windows messages then there are far better ways to do it.

Application.ProcessMessages is a way to stop your code looking as if it has crashed.

e.g.
REPEAT
  <Something long and CPU intensive>
UNTIL <Some condition>;

Without an Application.ProcessMessages, your code would look to the user as if it had crashed when in fact it was just working really hard

The Neil
0
craig_capelCommented:
To add to that.... its usefull where your doing For next loops.... for example...

var
h: hwnd;
begin
repeat //Do Work Start
h:=getforegroundwindow;
 if (h<>findwindow('shell_traywnd',nil))then
  showwindow(h,sw_minimize);
  application.processmessages;
  until (h = null) or (h = findwindow('shell_traywnd',nil));
application.Restoretopmosts;


Have A Go With That... something i put together for you, if you dont put in application.processmessages in, then you can make big problems for tight loops and code....

Hope you like that code :)

Craig C.
0
craig_capelCommented:
ok ok, before you point out to me i never did a for num:=1 to ??? do begin... i changed my mind... sorry :)
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

deroverCommented:
var
  Msg: TMsg;
begin
  while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do
  begin
    TranslateMessage(Msg);
    DispatchMessage(Msg);
  end;
  // no msgs to be dispatched <HERE>
end;



-Rover
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ptmcompCommented:
I agree with The Neil. You never should do this (- well there are a few exceptions if you have a very good knowlegde of the VCL and windows programming). If your program is doing hard work you should do this in a second thread. If you want to lock the application for users action, just disable the form. Some things you can solve using timers. But in the end it depends very on what you want to do.
Regards, ptm.
0
GurkanAuthor Commented:
Thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.