my question: how can I call a window method from the embedded passedCC OR is there another way to have a generic window using variable container controls ?
I forgot to tell you, that I would like to call the window method from the passedCC, which is just an object and does not know about the window,
I tried to use the real window name and the method name which works.
You need to create a mechanism that allows the container controls to request the owner window to do something (ie: an event).
This is one way you could do it:
Add a new class and change its super to ContainerControl (I will name it wContainerSuper). NOTE. The class you add must be a normal class and not a ContainerControl.
Create a new event definition to wContainerSuper (I will name it GetData).
Create a new method in wContainerSuper named GetData with the code RaiseEvent GetData.
Set the super class of your container controls to wContainerSuper.
Update your container control code to call Self.GetData in the appropriate place.
In your window add a new method named ProcessGetDataEvent with a single parameter pSenderObj As wContainerSuper. This will contain the code that the container controls can execute.
When you create and embed your container control you need to connect the container control GetData event to the window’s ProcessGetDataEvent:
AddHandler ContainerControlWhichHasBeenEmbedded.GetData, AddressOf ProcessGetDataEvent
NOTE. Remember to use a matching RemoveHandler when you no longer need to container control / before the window closes.
It is also worth noting that GetData / ProcessGetDataEvent can be changed to support parameters + return values.
There are multiple container controls and they need a way to communicate with the owner.
Tim Hare’s solution works but it means that they can only be embedded into Window1. If Johann wanted to do the same but with a Window2 then the solution would not work as-is. I imagine this could be solved via an interface though.
My solution does not care where the container is embedded as it just raises an event to whatever is listening.
No, I understand events. You’ve opted to have a middleman class (wContainerSuper) when you could just add Event Definitions to the ContainerControl that was designed. The only benefit to a middleman class that I know is to have multiple designed containers share the same events, and that doesn’t even work on iOS.
That’s why I ask why you went this route. OP only needs one container to talk to any kind of Window. A normal ContainerControl + Event Definition should suffice (and be a heck of a lot simpler).
thanks very much for your suggestions, I will tru the example with a super container class.
what it is all about:
I have a generic window using it for data entry, where I pass a container control (only 1 at a time ) with various data entry fields, and I use embedWithin to add it to the window.
it works great, but would like to be able to call a window method (if possible) .
if you have objects with same functionality you could use a interface.
in the ide at the right in inspector id interfaces choose …
obviously add a class interface with your method names before.
You can store this objects in a single or array from type yourinterfacename.
or pass your window object as reference and memory it,
you can access public methods then.
if you add a cc at runtime you can use addhandler for any cc defined event, you
would add your own method in the addhandler.
of course, you are so right, I know when it gets complicated than something is not quite right and one should rethink about the workflow and that’s exactly what I’m doing now,