Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sending Message ?

Posted on 1998-12-22
3
Medium Priority
?
146 Views
Last Modified: 2010-04-04
following is my simple event, but it's just work in single unit, how to place the same message event to any forms i want. Once sending the message, all the forms with that event will be fire. it's something like broadcast the message.please help me with a sample code.

const
SX_MESSAGE = WM_USER;
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  public
  procedure MYEVENT(var Msg : TMessage);message SX_MESSAGE;
end;

implementation

procedure TForm1.FormCreate(Sender: TObject);
begin
SendMessage(self.Handle,SX_MESSAGE,0,0);
end;

procedure TForm1.MYEVENT(var Msg: TMessage);
begin
showmessage('hello');
end;


0
Comment
Question by:qwertyuiopasdfghjkl
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 120 total points
ID: 1352631
To send the same message to all forms do this

var
  I : Integer;

for i := 0 to Screen.Formcount - 1 do
  SendMessage(Screen.Forms[i].Handle, SX_MESSAGE,0,0);

Cheers,

Raymond.

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1352632
Hi Raymond,

(1) Why not using Screen.Forms[i].Perform(SX_MESSAGE,0,0)?

(2) I'm not sure if he wants to know how to perform a broadcast message. However, it's just a part of the question. I think he wants to know how to easily add the event HANDLER to all the forms. Perhaps he should use a little component, what do you think?

qwert..., for what do you need that?

Regards, Madshi.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1352633
Ok...

Madshi: Yes .perform would also work.

qwert...: You can add the event to a base form class and then make sure all your forms are derived from that one. In this case you would type  the following code into a unit (don't create a form though!). Then when you create a form with New Form... change the declaration in the code so that the form is derived from TMessageForm instead of TForm (and then Robert is your fathers' brother!)

const
    SX_MESSAGE = WM_USER;
type
      TMessageForm = class(TForm)
      public
      procedure MYEVENT(var Msg : TMessage);message SX_MESSAGE;
    end;

Procedure TMessageForm.MYEVENT(var Msg : TMessage);

begin
// Do your stuff here
end;

Cheers,

Raymond.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

782 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