====== Broadcasting a message to all windows in a WinForms application ======
All VO users know about ''BroadcastMessage'' method from SSA example to etablish a communication system between different windows (Forms).
It’s very easy to implement this in X#. It’s also more powerful.
You can use "BroacastMessage" from EVERYWHERE in your code. There is even no need to identify a particular "Sender" (oSender: NULL_OBJECT) but every opened Form can receive the message by implementing a "BroadCastMessageReceive" method
PUBLIC FUNCTION BroadCastMessage(oSender AS Form, cMessage AS STRING, oExtra AS OBJECT) AS VOID PASCAL
LOCAL aParameters AS OBJECT[]
LOCAL oFormsList:= List
**Implementation example.**
Class xyz inherit Form
Method xyz_FormClosed(sender AS OBJECT, e AS System.Windows.Forms.FormClosedEventArgs) AS VOID
BroadcastMessage(SELF,"xyz_FormClosed",oUsefullThingOrNULLOBJECT)
CLASS MySpecialTextBoxControl inherit Textbox
Method xx()
BroadCastMessage(SELF :FindForm(), "Hello",SELF)
CLASS abc inherit Form
Method BroadCastMessageReceive(oSender as Form,cMessage as STRING,oExtra as OBJECT) AS LOGIC
do case
case cMessage=="xyz_FormClosed"
do something
// If you are sure no other form needs this message, you can return FALSE
RETURN FALSE
Case cMessage = « Hello » .and. oExtra IS MySpecialTextBoxControl
Local oTbox := < MySpecialTextBoxControl >oExtra As MySpecialTextBoxControl
Do something
endcase
RETURN TRUE //This means the Broadcast Function will continue his loop...
Code courtesy by Guy Deprez