Handling a ContainerControl like a RectControl?

I’m working on a layout mechanism and I have run into a situation where I can’t use my main function to get the position and size information from a ContainerControl. Here is my method signature:

GetControlInfo(theControl As RectControl) As arrSizePosition()

This is no issue if the Control passed is any other control, and I get back my array with the top, left, width, height values). When I pass a container, I get the error:

Parameter "theControl" expects class RectControl, but this is class ccBackupJobs.ccBackupJobs.

Is it possible to work around this so that I can deal with all of my ContainerControl-based custom controls?

Maybe overload the function:

GetControlInfo(theControl As EmbeddedWindowControl) As arrSizePosition()

You get back an array which implicitly has top left bottom right width height etc in some specific array index which is really not the best but…

perhaps return a REALBasic.Rect?

Oh EmbeddedWindowControl would have been nice to know about a couple weeks ago :stuck_out_tongue: Is it documented anywhere?
I ended up taking an overloaded approach that had a signature for RectControl and one for ContainerControl.

I now have the pair of functions defined as:

GetControlInfo(theControl As RectControl) As arrSizePosition() GetControlInfo(theControl As EmbeddedWindowControl) As arrSizePosition()

When I use that, the compiler complains that it doesn’t know which method to use:

There is more than one item with this name and it's not clear to which this refers.

I am calling it with the container explicitly called out:

theControlInfo = GetControlInfo(ccBackupJobs1)

ccBackupJobs1 is a container positioned on the Window in the IDE.

May the issue be that the compiler is not recognizing the container as a container and instead as the parent class as witnessed by the original error:

...but this is class ccBackupJobs.ccBackupJobs

EmbeddedWindowControl can be used in place of both RectControl and ContainerControl I think. Nope.

I believe what Jason is offering is these choices:

GetControlInfo(theControl As RectControl) As arrSizePosition()
GetControlInfo(theControl As ContainerControl) As arrSizePosition()

GetControlInfo(theControl As EmbeddedWindowControl) As arrSizePosition()

That’s how I understood it (have not had the opportunity to test)

The documentation is at least clear that ContainerControl is not a child of RectControl. They are both children of Object, but I like scoping it to EmbeddedWindowControl if that ends up working out.

Update: EmbeddedWindowControl did not work out. I’m getting “expects class but got” errors. I probably misunderstood what Jason was offering.

I suspect that makes at least two of us :).

Sorry - EmbeddedWindowControl is the runtime type:

GetControlInfo(theControl As RectControl) As arrSizePosition()
GetControlInfo(theControl As ContainerControl) As arrSizePosition()

Example project:

https://blog.xojo.com/wp-content/uploads/2018/10/overloaded.xojo_binary_project.zip

Me hearties… I think you took “National talk like a pirate day”, a bit too far :wink:

EmbeddedWindowControl is a RectControl, so that overload won’t work.

All of my arrays are now arrXXXXXXX() - it’s official and my company coding style handbook.
:stuck_out_tongue:

Thank you for this. Do you know where the documentation is?

I don’t believe it is documented. It is a hack (my opinion) related to the fact that the Control() function returns an array of RectControls, but a ContainerControl is derived from Window, not Control. Therefore, you cannot have a ContainerControl in the Control() array directly, so they had to have a place holder of some kind to represent the ContainerControl in the list of controls on the window. By itself, the EmbeddedWindowControl isn’t very useful, so you end up maintaining your own array of ContainerControls that you can manipulate as needed.