Embeded container control

I’ve yet to embed from code a container control but wanted to experiment some. In it’s simplest form I placed some controls in containerControl1. In the window1s open event I placed this code: ContainerControl1.EmbedWithin(Self, 50, 100) which was the example in XOJO language ref. When run this creates the error:

There is more than one method with this name but this does not match any of the available signatures.
ContainerControl1.EmbedWithin(Self, 50, 100)

I also tried activating this ContainerControl1 from a button in window1. ???

You’re not creating an instance of the ContainerControl to embed.

Var newCC as New ContainerControl1 newCC.EmbedWithin(Self, 50, 100)

[quote=494077:@Anthony Cyphers]You’re not creating an instance of the ContainerControl to embed.

Var newCC as New ContainerControl1 newCC.EmbedWithin(Self, 50, 100)[/quote]

Well darn, wouldn’t you know it!

Can these container controls be indexed so containing stored values could be saved and reloaded back in when reopened?

Well, you’d need to save a reference to your ContainerControls somewhere (maybe as an array property on your window), then you could use the myContainer.Control and myContainer.ControlCount:

[code]’// Scan through the controls on the CC
var intMax as Integer = newCC.ControlCount - 1
for intCycle as Integer = 0 to intMax

'// Check to see if it’s a TextField
if newCC.Control(intCycle) isa TextField then

'//  It is, so we can cast it to a TextField typed variable for
'    retrieving the Value property
var currentField as TextField = TextField( newCC.Control(intCycle) )

'// Create a MessageDialog just to show the value
var m as new MessageDialog
m.Show( currentField.Value )

end if
next[/code]

[quote=494083:@Anthony Cyphers]Well, you’d need to save a reference to your ContainerControls somewhere (maybe as an array property on your window), then you could use the myContainer.Control and myContainer.ControlCount:

[code]Var newCC as New ContainerControl1
newCC.EmbedWithin(Self, 50, 100)

'// Scan through the controls on the CC
var intMax as Integer = newCC.ControlCount - 1
for intCycle as Integer = 0 to intMax

'// Check to see if it’s a TextField
if newCC.Control(intCycle) isa TextField then

'//  It is, so we can cast it to a TextField typed variable for
'    retrieving the Value property
var currentField as TextField = TextField( newCC.Control(intCycle) )

'// Create a MessageDialog just to show the value
var m as new MessageDialog
m.Show( currentField.Value )

end if
next[/code][/quote]
Better yet, can they be used as a control array?

I’m not sure what you’re asking.

If you’re asking if you can store an array of ContainerControls on your window, then yes:

Private Property myContainers() as ContainerControl1

The best way to do what you want, though – as opposed to the looping method above – is probably to add a public method to your ContainerControl1 that returns the values of its children in the format you expect them to be in.

This may not be the best way to do this but let’s say I was to use the same containerControl with 10 slider values, in a control array(7) to set values for each day of the week. They would be embeded from code for each day chosen.

Assuming you have already made a Control Set of the sliders within the ContainerControl, named daySlider in this example, I would add a method to the ContainerControl that returns the values of the sliders, say in an array, something like:

[code]Public Function getDayValues() as Integer()
var arrReturn() as Integer
for intCycle as Integer = 0 to 6
arrReturn.AddRow( daySlider(intCycle).Value )
next

Return arrReturn
End Function
[/code]

[quote=494094:@Anthony Cyphers]Assuming you have already made a Control Set of the sliders within the ContainerControl, I would add a method to the ContainerControl that returns the values of the sliders, say in an array, something like:

[code]Public Function getDayValues() as Integer()
var arrReturn() as Integer
for intCycle as Integer = 0 to 6
arrReturn.AddRow( daySlider(intCycle).Value )
next

Return arrReturn
End Function
[/code][/quote]
I’m not sure I would gain anything going this direction. I’m struggling on how to redesign half a dozen windows that are used for setting preferences. A typical window may have up to a dozen controls and can store different prefs for each day of the week, 7 heating zones, two schedules for normal and summer mode. Also zone start heating times and zone temperatures for five periods in a day. When stored it ends up in a 5-dimensional array. I’m trying to take a new direction on how to accomplish this since I’m not taking advantage of XOJO abilities to reused code and encapsulation as I should. Any direction on this would welcome.

Unfortunately, I don’t have your project in front of me or detailed specs, so I can answer some questions, but I can’t really redesign your app on the forums.

Using the function in the ContainerControl that I posted before will add some encapsulation, and you can continue with that methodology to encapsulate everything further to have each Container, window, or class do it’s own heavy lifting.

I think you can do this with a single container control. See my comments on your other thread, which I am copying here.

[quote=494085:@Anthony Cyphers]I’m not sure what you’re asking.

If you’re asking if you can store an array of ContainerControls on your window, then yes:

Private Property myContainers() as ContainerControl1

The best way to do what you want, though – as opposed to the looping method above – is probably to add a public method to your ContainerControl1 that returns the values of its children in the format you expect them to be in.[/quote]

This intrigues me a little but I’m not sure where it would take me. I would assume I could have an array of instances of container controls that could have there own stored values in preferences for each instance of the ContainerControl. Would this be correct? The instances could be called up from the array() to be displayed, cloned to be modified then cloned back to be saved. Realistic?

Once you embed a container, you cannot un-embed it and then embed it again. You would have to hide them and leave them embedded, which may consume a lot of resources. I would personally reuse a single container control.

If you were to use a single container control what would be the advantage over just using a single window?

Encapsulating the controls that display the values and giving some separation from the buttons that select which set of settings to display and edit.