Interact with embedded ContainerControl

How do I refer to a control from within a containerControl that is embedded within a pagePanel?

Thanks

How was it embedded?

If you put it there at design time, then you just refer to things by their name:

MyContainerControl1.PushButton1.Caption = "Save"

If you added it there using EmbedWithin, then you’ll need to retain a reference to the control, but then you can also just refer to things by name as above.

It would probably be a better design to not refer to specific controls in this manner, however (encapsulation and all that).

[quote=31701:@Paul Lefebvre]How was it embedded?

If you put it there at design time, then you just refer to things by their name:

MyContainerControl1.PushButton1.Caption = "Save"

If you added it there using EmbedWithin, then you’ll need to retain a reference to the control, but then you can also just refer to things by name as above.

It would probably be a better design to not refer to specific controls in this manner, however (encapsulation and all that).[/quote]
How should I go about doing this? Thanks I want to make a better design choice, how do go about doing that.

You talk to the containercontrol from the outside by calling methods you define in the container. The container talks to the outside world through its events. Following Paul’s example, you might define a method, EnterEditMode, in the containercontrol.

Sub EnterEditMode()
   Pushbutton1.Caption = "Save"
   ...
End Sub

From the outside, you would call myContainerControl1.EnterEditMode and the container would do whatever in necessary. What this does for you is allow you to change the innards of the container without having to change the way you use it. You might decide that instead of a pushbutton, you want to use a bevelbutton with an icon. Then you just have to swap out the buttons and change the method.

Sub EnterEditMode()
   Bevelbutton1.Caption = "Save"
   Bevelbutton1.Icon = saveimage
   Bevelbutton1.IconDY = 20
   ...
End Sub

[quote=31719:@Tim Hare]You talk to the containercontrol from the outside by calling methods you define in the container. The container talks to the outside world through its events. Following Paul’s example, you might define a method, EnterEditMode, in the containercontrol.

Sub EnterEditMode()
   Pushbutton1.Caption = "Save"
   ...
End Sub

From the outside, you would call myContainerControl1.EnterEditMode and the container would do whatever in necessary. What this does for you is allow you to change the innards of the container without having to change the way you use it. You might decide that instead of a pushbutton, you want to use a bevelbutton with an icon. Then you just have to swap out the buttons and change the method.

Sub EnterEditMode() Bevelbutton1.Caption = "Save" Bevelbutton1.Icon = saveimage Bevelbutton1.IconDY = 20 ... End Sub [/quote]
What is the best way for multiple embedded controls? So in my case I want to refer only to the ContainerControl that is embedded within the current page in the PagePanel. Thanks

If you embed it at design time, then just call it by name. If you embed it at run time, then you need to keep a reference to it.

‘It would probably be a better design to not refer to specific controls in this manner’. I am trying to find the most efficient method. I have an idea and that is to use a timer within the embeddedControl, refer to a variable in the window to see when the button is pressed outside the contianerControl. But I would not be suprised that using a timer is not very efficient for the computer. Thankyou

Paul was not referring to the container, but rather the controls within the container. It is perfectly acceptable to refer to the container by name, as it is owned by the window. But the controls in the container are off limits to window code.

I like to shadow the control properties I want to have access to by adding computed properties to the containerControl. That way I can treat the relevant properties that I need access to as properties of the ContainerControl.

Yeah thats not shadowing.
Shadowing is when a subclass redefines a property of it’s parent class.

What you’re doing is bridging - so the container appears to have a property that is actually from one of the controls in the container & thats a perfectly acceptable technique.

Well, there’s nothing stopping you from doing doing so. You can reference controls directly if they are public scope.

self.containercontrol1.textfield1.text = "Something" is perfectly acceptable. But it does sort of defeat the purpose of having a container to begin with though.

Maybe not interessting anymore, but why not using computed properties within the containercontrol?
In most cases you have a certain target within the control in mind using a property to set (e.g. the container control is a customized textfield with a standard textfield using the cueText property). So just add a computed property to your container, name it like the original one (e.g. cueText) and use the getter and setter method to set or get the properties to the controls within the containers controls.

…ah forgot to mention. It must be public, but this should this property be anyway…like a standard control’s