Using messages to notify TFrames they should refresh underlying datasets

155 Views Asked by At

I am using TFrames to split different parts of a form (visual elements and code) into different units. For example, if my form is an invoice, I have Frame#1 showing the client, invoice date and total amount and Frame#2 containing a list of products with quantity, product name and amount.

Whenever the user is adding/editing/removing a product line, I would like Frame#2 to notify all frames of the change. Frame#1 would then recalculate the total amount.

I would like to use Windows messages to do this but I'm not sure this is possible.

I have defined (in the DataModule that all units use) :

Const Message_ProductLineUpdate = WM_USER + 101;

Then in Frame#1 I defined my "handler" :

procedure RefreshAmount(var Msg:TMessage); message Message_ProductLineUpdate;

And in Frame#2, when the change occurs, I do :

PostMessage(Application.Handle,Message_ProductLineUpdate,0,0);

But RefreshAmount is never called. I first tried :

PostMessage(Self.Handle,Message_ProductLineUpdate,0,0);

But I guess the message is "dispatched" to the sending frame exclusively. I am also guessing that my handler is only listening to messages posted to its own Handle.

Is it possible to have all frames hooked to the Application's messages ? What is the correct way to deal with that situation ?

0

There are 0 best solutions below