Embeded container control

  1. last week

    Clifford C

    Jun 26 Port Angeles, Washington
    Edited last week

    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)
  2. Anthony C

    Jun 26 Testers, Xojo Pro, XDC Speakers, Third Party Store, Forum Moderators, MVP Answer GraffitiSuite Developer
    Edited last week

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

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

    Jun 26 Port Angeles, Washington

    @Anthony C You're not creating an instance of the ContainerControl to embed.

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

    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?

  4. Anthony C

    Jun 26 Testers, Xojo Pro, XDC Speakers, Third Party Store, Forum Moderators, MVP GraffitiSuite Developer
    Edited last week

    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:

    '// 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
  5. Clifford C

    Jun 26 Port Angeles, Washington

    @Anthony C 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:
    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

    Better yet, can they be used as a control array?

  6. Anthony C

    Jun 26 Testers, Xojo Pro, XDC Speakers, Third Party Store, Forum Moderators, MVP GraffitiSuite Developer
    Edited last week

    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.

  7. Clifford C

    Jun 26 Port Angeles, Washington

    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.

  8. Anthony C

    Jun 26 Testers, Xojo Pro, XDC Speakers, Third Party Store, Forum Moderators, MVP GraffitiSuite Developer
    Edited last week

    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:

    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
  9. Clifford C

    Jun 26 Port Angeles, Washington

    @Anthony C 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:
    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

    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.

  10. Anthony C

    Jun 26 Testers, Xojo Pro, XDC Speakers, Third Party Store, Forum Moderators, MVP GraffitiSuite Developer
    Edited last week

    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.

  11. Tim H

    Jun 26 Portland, OR USA

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

    I would structure your data like this:

    • Your basic object is a zone.
    • A zone contains settings for each day of the week
    • Each day of the week contains 2 sets of settings: Normal and Economy, as well as an Away temp
    • Each set of settings contains 5 periods
    • each period contains values for: Slider A (time), Slider B (temp) and Checkbox (active)

    Each of those is a separate class. Your prefs window is displaying a set of settings. You can create a container control to display the settings and pass it a Settings object to display. Then you would also give it a method that returns a settings object that represents the changes the user made.

    As the user clicks the buttons on the bottom of the screen you would retrieve the current state of settings and store it in the current day of week, then get the settings for the new zone/day and pass them to the container to display/edit.

  12. 6 days ago

    Clifford C

    Jun 27 Port Angeles, Washington

    @Anthony C 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 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?

  13. Tim H

    Jun 27 Portland, OR USA

    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.

  14. 4 days ago

    Clifford C

    Jun 29 Port Angeles, Washington

    @Tim H 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?

  15. Tim H

    Jun 29 Portland, OR USA

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

or Sign Up to reply!