Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Notifying forms of global changes


How do I tell all created (and even hidden), forms of an application that some global option has changed?   

    One way is to create a user message, and use the preform method to send the message to all forms in the Screen.Forms array. Example:

    {Code for Unit }

    const UM_MyGlobalMessage = WM_USER + ;

    type TForm = class(TForm) Label : TLabel; Button : TButton; procedure FormShow(Sender: TObject); procedure Button Click(Sender: TObject); { Private declarations } private procedure UMMyGlobalMessage(var AMessage: TMessage); message UM_MyGlobalMessage; public { Public declarations } end;

    var Form : TForm ;

    implementation

    {$R *.DFM}

    uses Unit2;

    procedure TForm .FormShow(Sender: TObject); begin Form2.Show; end;

    procedure TForm .UMMyGlobalMessage(var AMessage: TMessage); begin Label .Left := AMessage.WParam; Label .Top := AMessage.LParam; Form .Caption := 'Got It!'; end; procedure TForm .Button Click(Sender: TObject); var f: integer; begin for f := 0 to Screen.FormCount - do Screen.Forms[f].Perform(UM_MyGlobalMessage, 42, 42); end; {Code for Unit2}

    const UM_MyGlobalMessage = WM_USER + ;

    type TForm2 = class(TForm) Label : TLabel; private { Private declarations } procedure UMMyGlobalMessage(var AMessage: TMessage); message UM_MyGlobalMessage; public { Public declarations } end;

    var Form2: TForm2;

    implementation

    {$R *.DFM}

    procedure TForm2.UMMyGlobalMessage(var AMessage: TMessage); begin Label .Left := AMessage.WParam; Label .Top := AMessage.LParam; Form2.Caption := 'Got It!'; end;

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use