Solved

Sending Message ?

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 100
Working with hours 3 54
Dev Express grid collapse 2 44
Delphi problems to abort a printjob 9 17
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now