How to talk from embedded containerControl to the window

At runtime I use emdedWithin to add ContainerControl-A to the window.
Works ok,
I would like to tell ContainerControl-B that some data have changed in ContainerControl-A. I could do it also via the window of course.

But how can I do that ?

Have a look at my “Day of Month Picker” at Xojo + Alfred which uses a delegate for this.

you could define and raise an event

Nope, that only works if you actually embed a container and not when you use embed within.

Beatrix, I know how delegates work, but this one is embedded at run time, and the containerControl does not know anything about the window.
I red about addHandler, I do not know exactly how that works, but I also red you should avoid addHandler. But from what I can see, addHandler would be my only choice, can’t think of something else.

In ContainerControl-B I would have a Property called myContainerControl-A. In the Window Open Event, set ContainerControl-B’s myContainerControl-A Property to be ContainerControl-A on the Window. When ContainerControl-B needs access to myContainerControl-A, it is all there (check for Nil first, just in case!).

You can similarly place a Property of ContainerControl-B (called myContainerControl-B) inside ContainerControl-A then, if ContainerControl-A changes, you need only update the Property myContainerControl-B.

My code uses the same design.

thanks all for your help,

David gave me the hint with the property’s.
I created a subclassed container control, which I always avoided to do, because I was not quite sure how it works.
that subclassed cc holds a property of cc_B, which I can load after embedding cc-A. now I just call a Methode of cc_B and all works fine.

f course cc_A and cc_B have to be of type subclassed cc.
learned something new

thanks to all again

at runtime
addHandler just link a event to a method (because you can not add this event at design time).
https://documentation.xojo.com/api/code_execution/addhandler.html


Ashampoo_Snap_Dienstag, 4. Januar 2022_13h2m13s_001_Xojo - Work Schedule.xojo_binary_project
Ashampoo_Snap_Dienstag, 4. Januar 2022_13h1m25s_001_Xojo - Work Schedule.xojo_binary_project

thanks Markus,
will try it too

The more general way is an Observer pattern or event notification bus. There’s a forum thread and article that talks about this and refers to the built-in ActionSource / ActionNotificationReceiver. It’s also not too hard to implement your own if this isn’t sufficient (and there are several threads on the forum about the Observer pattern): you have a manager class anyone can call to register to receive a notification for some event name (which can just be a string, so very flexible). When a caller registers for an event (in your case, ContainerControl-B), it gets added to a list for that event. Another object (ContainerControl-A) can then call the manager to notify that the event has occurred; the manager then walks the list calling those that have registered to let them know the event occurred and where it came from (call a callback method on ContainerControl-B saying event “A-Changed” occurred, maybe with a reference to ContainerControl-A). This typically will be implemented through a common interface so the manager (and maybe the objects, as well) can talk to each other.

GitHub - ianmjones/EventBusIJ: A simple synchronous Event Bus for Desktop and Web Edition Real Studio projects. still works quite well for scenarios like this

thanks Matthew and Ronny,
sound interesting, will see what I can do, I will certainly try something