EmbedWithin vs. AddControl

I’m using EmbedWithin to add newly instantiated DesktopContainers to a DesktopCanvas. I see there is also AddControl (although I’ve not checked to see if I could use that instead). But is there anything that one can do with one method that can’t be done with the other?

EmbedWithin automatically sets the Parent. AddControl does not. You have to do that yourself if it matters. In particular, if you EmbedWithin, the container will obey the Visible property of the canvas. Hide the canvas, the container is hidden, too. With AddControl, the control will just hover over the canvas. Hiding the canvas has no affect on the control.

The other obvious difference is that AddControl instantiates a single control, whereas a container is usually several controls working together to provide specific functionality.

embedWithin is the classic public facing API for adding containers to windows and such.

From what I understand about addControl, it was originally private API that was made public.
It’s possible that addControl is what Xojo actually uses to build and layout your window when it opens.

Thanks for those details which are not in the docs. They don’t actually affect me, but it looks like EmbedWithin is the one to stick with. Setting the parent is important, as I may add a number of the containers, align them, and then scroll them if necessary.

1 Like