Subclassing ContainerControl

With most of the Xojo controls, if I drag them into the main Contents area, Xojo creates a subclass of the control and then I can modify it by adding properties and methods to it.

I can then drag instances of my new control into windows and use it in other parts of my interface.

A ContainerControl from what I have read is always a class, and you can’t drag a containerControl into a window. You can drag it into the contents area, and then drag an instance of it into a window however.

But what I want to do is to add some standard properties to a few different types of containers without having to duplicate the properties in each type of container. I want to subclass a ContainerControl. But for some reason in Xojo I am not allowed to declare that the super class of a ContainerControl is another ContainerControl that I’ve extended.

Here is what I am doing:

Drag ContainerControl to the contents area and name it AppContainer
Add property ParentWindow of type Window
Drag ContainerControl to the contents area again and name it Container1
Change its super to AppContainer

When running, I get this error:
“The project item Container1 can not inherit from a window (AppContainer).”

How do I create an extended ContainerControl with additional properties and methods, that I can then subclass in my application?

Thanks,

Mars

You would do this in the same way you would do it for a window class. Namely, use Add Class to create a brand new class and set its Super to ContainerControl. Add your methods and properties to this new class (note that it has no UI, only methods and properties). Now you can drag an instance of your new class into your contents area and add UI elements to it, along with the methods and properties that are unique to this control.

You can create a subclass of the Window and ContainerControl classes. But once you drag one into your contents area, it becomes an amalgam of instance/module/subclass and you cannot further subclass it. You can only create instances of it.

Thanks Tim That’s perfect. I didn’t know yet how to subclass a window either but gathered it would be the same way.

When I Insert Class (that’s what you mean by “Add Class” above) it gets added to the Contents area in the navigator anyway. So I am not quite sure how you would drag it into the contents area from there.

If I make a new class called AppContainerClass, and set its super to ContainerControl, none of the normal properties that are available in a ContainerControl appear in the class in the inspector. It also has no layout to add other controls to it. But…

If I then add a new ContainerControl called SpecificAppContainer, and then set it’s super to AppContainerClass, I can then add controls to that and it compiles and runs. But I can’t access the specific properties I set in my AppContainerClass in an instance of the SpecificAppContainer.

Assuming AppContainerClass has a property called ParentWindow of type Window,

Dim AppWindow as Window

...

Dim appC as new SpecificAppContainer
AppWindow.AppendContainerToListForCanvas(appC)
appC.ParentWindow = AppWindow

That works.

Is that what you were meaning above? Or is there a better way to do it? I’m new to Xojo and grateful for your pointers.

[quote=33673:@Michael Mars Landis]Thanks Tim That’s perfect. I didn’t know yet how to subclass a window either but gathered it would be the same way.

When I Insert Class (that’s what you mean by “Add Class” above) it gets added to the Contents area in the navigator anyway. So I am not quite sure how you would drag it into the contents area from there.
[/quote]
Yes, Insert -> Class is what I meant. I’m not used to Xojo that well. I still do most of my coding in Real Studio.

[quote]If I make a new class called AppContainerClass, and set its super to ContainerControl, none of the normal properties that are available in a ContainerControl appear in the class in the inspector. It also has no layout to add other controls to it. But…
[/quote]
That is as it should be. You’re defining the class logic - you’re adding properties and methods. There is no layout and there is nothing to display in the inspector.

[quote]If I then add a new ContainerControl called SpecificAppContainer, and then set it’s super to AppContainerClass, I can then add controls to that and it compiles and runs. But I can’t access the specific properties I set in my AppContainerClass in an instance of the SpecificAppContainer.
[/quote]
You should be able to access everything you added to AppContainerClass. You have to adjust the Inspector Behavior of AppContainerClass before you add SpecificAppContainer in order to get any new properties you added to AppContainerClass to show up in the inspector. But you can still access them all in code.

Thanks Tim that’s very helpful. I very much appreciate you sharing your experience.

  • Mars