Solved

Sending Message ?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

22 Experts available now in Live!

Get 1:1 Help Now