IsA ContainerControl

To demonstrate my confusion - I have a simple Window that contains a text area, I create a ContainerControl and place a PushButton inside it, I then drag the ContainerControl into the Window. In my Window.Open event handler I have the following code:

[code]
for i as integer = 0 to self.ControlCount - 1

dim c as Control = self.Control(i)
dim ti as Introspection.TypeInfo = Introspection.GetType(c)
dim isAContainerControl as boolean

if c IsA ContainerControl then
  isAContainerControl = true
end

textArea1.AppendText("Control " + str(i) + " is a " + ti.FullName + " ContainerControl = " + str(isAContainerControl) + EndOfLine)

next

for i as integer = 0 to ContainerControl11.ControlCount - 1

dim c as Control = ContainerControl11.Control(i)
dim ti as Introspection.TypeInfo = Introspection.GetType(c)
dim isAContainerControl as boolean

if c IsA ContainerControl then
  isAContainerControl = true
end

textArea1.AppendText("Control " + str(i) + " is a " + ti.FullName + " ContainerControl = " + str(isAContainerControl) + EndOfLine)

next[/code]

The output in the TextArea is as follows:

Control 0 is a TextArea ContainerControl = False
Control 1 is a EmbeddedWindowControl ContainerControl = False
Control 0 is a PushButton ContainerControl = False

Why isn’t the ContainerControl (shown in the TextArea output as Control 1) on my form testing logically true with IsA ContainerControl?

The Language Reference says:

The IsA operator returns True for the object’s own class as well as the super class from which that class was derived, all the way to the Object class. IsA will report that all classes ultimately derive from Object.

If I change the test to:

if c IsA Window then… it also fails but the class hierarchy in the Language Reference shows Object<-Window<-ContainerControl

try IsA EmbeddedWindowControl

I could swear that I tried that but maybe didn’t type the ‘dd’ of Embedded.

But, it is a ContainerControl so why is its FullName = “EmbeddedWindowControl”?

As a ContainerControl it should be a subclass of Window according to This which conflicts with the first line of ‘Notes’ in this This and so should I at least be able be able to cast it to Window to access its ControlCount and Control properties? If I try then I get an IllegalCastException. EmbeddedWindowControl does not have ControlCount and/or Control properties so how can I loop through the controls in my ContainerControl when my ContainerControl is just a control in a Form Window but does not appear to be a ContainerControl anymore?

Is it too late and I am missing something obvious? I know that I could reference it by name but that is messy when I have ContainerControls embedded in ContainerControls. I just want to loop though all of the controls in a Window and if the control is a Window or ContainerControl then loop through all of the controls in that too.

The problem is that ContainerControls were implemented half as a window and half as a control and a lot of the implementation details seeped through. EmbeddedWindowControl isn’t really even a documented class, but is what you see in the control list.

It’s all quite unfortunate.

:slight_smile: I got the feeling that there was a bit of magic going on with ContainerControls. So is there a way to loop though the controls in an EmbeddedWindowControl (including other EmbeddedWindowControls within it) without having a reference to the ContainerControl? Or maybe a way to get back to the ContainerControl from the EmbeddedWindowControl?

Here is a post from the old forum with one way of doing it.