0

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 ?

6
  • Which Delphi version? Commented Jan 6, 2020 at 20:51
  • @UweRaabe Delphi 10.3.2 (VCL exclusively) Commented Jan 6, 2020 at 21:06
  • Might be easier in the long run to use LiveBindings instead of rolling your own change notification and synchronization implementation. Commented Jan 6, 2020 at 21:41
  • 2
    Perhaps using System.Messaging could be an option. Commented Jan 6, 2020 at 22:41
  • 1
    We use System.Messaging for exactly this. We have several frames, each descended from a base frame, that need to communicate with the application. We use customised messages to move data and requests back and forth. Malcolm Groves wrote a blog entry on this (which is where we got started): malcolmgroves.com/blog/?p=1372 Commented Jan 7, 2020 at 4:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.