When your component changes global settings that affect all of the controls in a form or other container, you may want to send a message to those controls so that they can update themselves appropriately. Not every control may need to respond to the notification, but by broadcasting the message, you can inform all controls that know how to respond and allow the other controls to ignore the message.
To broadcast a message to all the controls in another control, use the Broadcast method. Before you broadcast a message, you fill out a message record with the information you want to convey.
var Msg: TMessage; begin Msg.Msg := MY_MYCUSTOMMESSAGE; Msg.WParam := 0; Msg.LParam := Longint(Self); Msg.Result := 0;
TMessage Msg; Msg.Msg = MY_MYCUSTOMMESSAGE; Msg.WParam = 0; Msg.LParam = (int)(this); Msg.Result = 0;
Then, pass this message record to the parent of all the controls you want to notify. This can be any control in the application. For example, it can be the parent of the control you are writing:
It can be the form that contains your control:
It can be the active form:
It can even be all the forms in your application:
for I:= 0 to Screen.FormCount - 1 do Screen.Forms[I].Broadcast(Msg);
for (int i = 0; i < Screen->FormCount; i++) Screen->Forms[i]->Broadcast(Msg);
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!