Solved

Sending Message ?

Posted on 1998-12-22
3
141 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 30 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 67
delphi parse string to params 3 137
How to renew a Delphi rad-studio licence? 5 69
PHP preg_replace code convert to Delphi 14 68
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 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