troubleshooting Question

Trouble with broadcasting messages (TWinControl)

Avatar of rainwise
rainwise asked on
4 Comments1 Solution860 ViewsLast Modified:
{ Delphi 7 on XP Pro}
I am trying to send a custom broadcast message to all components within my application. I can send a custom message using "PostMessage" from within the main form and the forms handler gets it fine. If I try a broadcast the handler doesn't catch it. The Delphi help shows how to send the broadcast message but not how to trap them.  Could someone provide a code snippet to illustrate how to post and catch a custom broadcast  message. Here are some of the key functions from my test program:


private { Form1 }
 procedure MessageHandler(var M: TMessage); message MY_MESSAGE;

{ The message handler for the form }
procedure TForm1.MessageHandler(var M: TMessage);
begin ......

procedure TForm1.FormCreate(Sender: TObject);
  Msg.Msg := MY_MESSAGE;
  Msg.WParam := 0;
  Msg.LParam := Longint(Self);
  Msg.Result := 0;

  self.Broadcast(Msg); // This doesn't work
//  PostMessage(handle,MY_MESSAGE,0,0); // this does work
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros