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

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Starting up a Project
Suggested Courses
Course of the Month8 days, 2 hours left to enroll

765 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