• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

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
0
Gurkan
Asked:
Gurkan
1 Solution
 
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now