Getting a reference to the Control owner’s window

In an Extend method to the ListBox Control, I have this code that compiles but crash at run time with a NilObjectException.

The “offending” line is:

The_Left   = List.Parent.Left

I tried:

The_Left = (List.Parent.Left)

and that failed too…

Some minutes later after a glass of cold water…

[code]Dim w As RectControl

w = List.Parent
The_Left = Str(w.Left)[/code]

I got the same crash.
Nota: w As Window leads to an error at compile time:

“Expected Window but got RectControl"

BTW: I want to get and store the window position / size at save file time to be able to restore it at load time.

Any idea of how to achieve that ?

BTW: fn-Delete (OS X) does not works at that time. Once I really noticed that, I quit Xojo, reload it (double click on the project I was working on), click to open an event and click in the code editor: fn-Delete works now.

I found a (bad) solution: use Window(0) works, but this is bug prone because I may have another open window (a windoid or any other possible window).

self.left?

Self refers to the immediate parent window/container control of a control
.TrueParent always refers to the window that the control is physically located on, regardless of how many containers it is in…

Parent is the CONTROL that this control is sitting on. Most of the time, it is Nil. What you want is

the_Left = List.Window.Left

Tim: That’s it!!!

I do not checked in the IDE, but that is what I wanted to do. Why I used .Parent is unknow, but that is what I wanted to do !!!

Interesting. Thanks Shao

I’ve never used a container control as I’ve used personal edition for nearly all the time I’ve used RealBasic.
So self always means ‘the parent window’ in all my apps, but its good to know about this for the future.
It would probably have worked here too if no container was in use.

I can confirm what I wrote earlier: this is the correct answer. It works fine.

Thank you all.