Why does a containercontrol not have a name property ? -> search CC by Name it works !

but you can use it’s name in the IDE window editor ?
is there another way to get a containercontrol by it’s name ?
do I need to fill a FR ?
thanks.

A ContainerControl class has a Name property. Each instance on a window has a Name property. The only exception is dynamically embedded ContainerControls.

If you mean in code, then you have to check for the EmbeddedWindowControl instance:

For i As Integer = 0 To ControlCount - 1 If Control(i) IsA EmbeddedWindowControl Then // Name looks like _Window1._wrapper_ContainerControl11 If EmbeddedWindowControl(Control(i)).Name.InStr("._wrapper_" + "ContainerControl11") > 1 Then // do something with it End End Next

the containercontrols I want to find name are created with the IDE, they are not dynamic.
how can I find them ? with the EmbeddedWindowControl compare ?

Yes, all ContainerControls instances show as EmbeddedWindowControl in a window a runtime. But you will not get the actual ContainerControl instance, the instance shows as EmbeddedWindowControl (a subclass of Canvas). And therefore you cannot cast EmbeddedWindowControl to ContainerControl.

[quote=354292:@Jean-Yves Pochez]but you can use it’s name in the IDE window editor ?
is there another way to get a containercontrol by it’s name ?
do I need to fill a FR ?
thanks.[/quote]
yet more magic the IDE does :slight_smile:

If you’re creating them in the IDE, not dynamically, then why not just use the name of it right in your code instead of hunting it down dynamically ?

I want to have a list of the items I have to hide/unhide at runtime, so a group of items.
I was using a string array, or a string with all controls separated by commas.
this worked fine, until I met a containercontrol !

Apart from that, I just don’t understand why you can access all window items with their name, and not the containercontrol ?

A ContainerControl is a subclass of Window, hence the wrapper’s name EmbeddedWindowControl – which is a subclass of Canvas – when it appears as an instance in a window. It is a pity that EmbeddedWindowControl does not have a property EmbeddedWindowControl.ContainerControl As ContainerControl which allows access to it.

well even a window has a Name property :wink:

No, it does not:

MsgBox Window1.Name // does not compile // Error: Type "Window1.Window1" has no member name "Name"

For i As Integer = 0 To ControlCount - 1 If Control(i) IsA EmbeddedWindowControl Then // Name looks like _Window1._wrapper_ContainerControl11 If EmbeddedWindowControl(Control(i)).Name.InStr("._wrapper_" + "ContainerControl11") > 1 Then // do something with it End End Next

Eli,
your solution is nice, but there is still a problem:
once I have the EmbeddedWindowControl with the name I want, I cannot cast it to a ContainerControl ? I get an IllegalCastException.
so I know I have the containercontrol, but I cannot return it and use it …
any bright idea about this ?

[code] Dim iterator As Runtime.ObjectIterator = Runtime.IterateObjects()

Do Until Not iterator.MoveNext()
If iterator.Current IsA ContainerControl Then
Dim cc As ContainerControl = ContainerControl(iterator.Current)
If cc.Handle = ewc.Handle Then // ewc is the EmbeddedWindowControl
// Now we have the correct ContainerControl
Exit
End
End
Loop[/code]

too much. thanks again and again.

You cache the ewc.Handle – ContainerControl relations (with WeakRef), so that on subsequent calls you can do:

If dict.HasKey(ewc.Handle) Then // get it from the dictionary Else // iterate over runtime objects // add the "pair" to the dictionary End
Maybe as an Extends function called .AsContainerControl() on EmbeddedWindowControl?

I think I have better register my containers to the window at the opening.
the iteration in all the items of the app is not very optimized for me.
so, I will have the list of all containers in a window property that way it should be easier.

That’s what I meant with cacheing:

Function AsContainerControl(Extends ewc As EmbeddedWindowControl) As ContainerControl Static dct As New Dictionary() Dim ewcHandle As Integer = ewc.Handle Dim retval As ContainerControl = Nil If dct.HasKey(ewcHandle) Then Dim wr As WeakRef = dct.Value(ewcHandle) If wr.Value IsA ContainerControl Then retval = ContainerControl(wr.Value) End Else Dim iterator As Runtime.ObjectIterator = Runtime.IterateObjects() Do Until Not iterator.MoveNext() If iterator.Current IsA ContainerControl Then Dim cc As ContainerControl = ContainerControl(iterator.Current) If cc.Handle = ewc.Handle Then retval = cc Exit End End Loop dct.Value(ewcHandle) = WeakRef.Create(retval) End Return retval End

for the records, I was able to get the name of the containercontrol, using introspection.
using getype on the iterator.current gave this info in the Name field.

[code]Public Function GetContainerControlByName(extends aWindow as window, aName as String) as ContainerControl

If aWindow<>Nil Then
Dim o As Runtime.ObjectIterator = Runtime.IterateObjects

While o.MoveNext
  If o.Current IsA ContainerControl And ContainerControl(o.Current).Window Is aWindow  Then
    Dim t As Introspection.TypeInfo = Introspection.GetType( o.Current)
    If t.Name = "_wrapper_"+aName Then
      Return ContainerControl(o.Current)
    End If
  End If
Wend

end if

return nil

End Function
[/code]