Getting Frustrated On How To Find My Way Up The Window And ContainerControl Hierarchy

I am having problems trying to work out what code to use to find the best way to access the ContainerControl for a ContainerControl for a RectControl.

So if I would want to use something like:
‘me.window.window’

But the window type doesn’t seem to have a window property, so what do I do to best achieve this? Use the Parent property somehow? Cast the window property to a ContainerControl? What?

Thanks for any help

Start a loop.
If Parent is not Nil you have the RectControl containing the control. To go further up restart the loop with this RectControl.
Else if Window is equal to TrueWindow you have reached the actual window. Exit the loop.
Else Window is the ContainerControl containing the control.
Repeat from start.

Parent = the control that I am lying on top of and which fully encloses me.
Window = the container or window that I am in.
TrueWindow = the outermost window containing me an any containers I may be nested in.

If you want the window directly, use TrueWindow. If you want to walk the hierarchy, use a local variable and loop.

Edit: what Eli Ott said.

The important thing is the correct order (as both Parent and Window can be not nil at the same time). AFAIK you first test for Parent, and then – if Parent is Nil – for Window.

I don’t see any need to look at Parent for this. Loop over Window until you get a Window instead of a ContainerControl.

Thanks for the advice. I suppose I will create a method to do this. Thanks