Delphi - Loop and Process Messages

Posted on 2003-02-26
Medium Priority
Last Modified: 2010-04-17
If you make a delphi application and want the application to process messages while in a loop you type like this:
variable := 'mofasablablawhateverdontmindthisstoopidstring';

Application.ProcessMessages; // this here is the thang...
while variable = '';

Here's the question...

How do you make the same but in a component(derived from TComponent)?
Question by:OryX

Accepted Solution

xyzzer earned 200 total points
ID: 8031778
I'm not sure if there's such a method for a component, but if I had to hack into it I would do it this way:
Use the (WinAPI) GetMessage function:
BOOL GetMessage(
    LPMSG lpMsg, // address of structure with message
    HWND hWnd, // handle of window
    UINT wMsgFilterMin, // first message
    UINT wMsgFilterMax // last message
- to get all the messages from the queue.
Then, assuming that Your TComponent is a TWinControl - it has a Handle property, which You can compare with the handle from lpMsg (*MSG) and if the handles are the same - send the messages back to the queue:
LRESULT SendMessage(          
    HWND hWnd,
    UINT Msg,
    WPARAM wParam,
    LPARAM lParam
- and use ProcessMessages method afterwards - as it does it for the whole application. With filtered out messages You should get something like the thing You need.
Just remember to send the messages with different window-handles back to the queue afterwards.
Maybe there's a better method though...
You have to remember to put the messages from the queue in some sort of an array or list to be able to send them back for processing.


Expert Comment

ID: 9447479
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Independent Software Vendors: 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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Simple Linear Regression

571 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