containercontrol inheritance

  1. 4 years ago

    Hello Xojo Developers,

    this is my first post here.
    I found out an interesting behavior of the Container Control that I would like to share with you.

    As you all probably know it is not possible to inherit from a Container Control once you've put controls to it in the design editor.
    I always found this annoying when you want to reuse the container control and only rearrange the controls you have added to it.

    Now I have found a nice workaround:

    Define the container control as a class and add the controls as properties.
    You can code all the logic in this class. Event handling is a bit tedious though, as you have to use addHandler.

    Now you can add a container control to the project which inherits from your class and and place a control for every control property.

    In the constructor of the new container you assign the controls from the layout to the control properties:

    parentTextfield = layoutTextfield
    parentButton = layoutButton

    Now you can reuse the container with different layouts or add additional controls and functionality.

    Greetings from Germany
    Martin

  2. Eli O

    is not verified 29 Jan 2016 Europe (Berlin, Germany)
    Edited 4 years ago

    You can inherit from a container control, but you can only subclass and add code, you cannot subclass and add controls.

  3. Dear Eli Ott,

    thank you for your answer but you missed the point.
    I mean something like this:

    Protected Class CCParent Inherits Containercontrol
    Sub doSomething()
      MsgBox txtParent.Text
    End Sub
    
    Protected txtParent As TextField
    End Class
    
    Sub doSomething()
      MsgBox txtParent.Text
    End Sub
    End Class

    Now put in a Containercontrol in design mode and inherit from CCParent

    Sub constructor()
      txtParent = txtChild //assign reference from actual control to inherited textfield property 
    End Sub
    
    Sub Action()  //push button added in design mode
      doSomething
    End Sub
  4. Eli O

    is not verified 29 Jan 2016 Europe (Berlin, Germany)

    @MartinOsterbeck ... but you missed the point.

    No I didn't. I was only referring to this sentence which is incorrect:

    @MartinOsterbeck ... it is not possible to inherit from a Container Control once you've put controls to it in the design editor

  5. 7 months ago

    Julia T

    10 Feb 2019 Sandy Hook, Connecticut

    That's just what I was looking for to ease the pain of accommodating multiple mobile device screen sizes and orientations with a web app. I'd had the same idea but gave up when the IDE did not offer WebContainer as a possible superclass to my logic-performing object, and did not offer my logic-performing object class (subclassed from WebContainer) as a super for the UI WebContainer. Turns out if you just type them in it works, yay!

or Sign Up to reply!