Cannot embed a closed ContainerControl

I have a personal project (a simple text editor) I’ve been working on over several months (when I have the energy and headspace). And I have one feature I’ve been putting off until now, because I knew there might be some issues.

Using Xojo 2021r1.1 for a Desktop project on macOS (10.15.7).

I need to move an instance of an embedded ContainerControl (which contains an HTMLViewer-based editor), which I’ll call AceCC (which is also attached to a PagePanel using *.EmbedWithinPanel) from within one ContainerControl to a whole different ContainerControl (and attach it to another PagePanel).

In other words, move an active instance of an embedded ContainerControl from a “source” parent Container to another “target” parent Container.

I am able to move my reference for the AceCC instance from one ContainerControl to the other okay, but when I go to do the second EmbedWithinPanel call (in the “target” Container), I get an UnsupportedOperationException that says “Cannot embed a closed ContainerControl

AceCC.EmbedWithinPanel(Self.contentPanel, newPanelIndex, 0, 0, Self.contentPanel.Width, Self.contentPanel.Height)

Note: I am able to interact with the AceCC instance fine, like to use RemoveHandler for events in the source ContainerControl, and AddHandler in the new target ContainerControl, but the final target embed chokes.

During removal of the embedded ContainerControl from the “source” Container, I do some cleanup that involves calling Close on the AceCC Container (which I can avoid doing), but I suspect it is the call to the “source” PagePanel.RemovePanelAt that is actually closing the Container in my instance.

What do you folks think?

I do have a workaround in mind, but I would lose some state information inside the AceCC instance, such as the Undo history. The workaround involves creating a New instance and copying various property information across, then destroying the original.

Is it possible to keep an embedded ContainerControl from closing when I move it like this?

Any insight or advice would be greatly appreciated.

And thank you for reading through my rambling. I hope it made sense :crazy_face:

I think the best way forward would be the workaround you seem to be considering. Creating a new instance. Ace Editor supports implementing a custom UndoManager via the UndoManager.execute method and supplying deltas, so that may be the way to go. It’s something I’ve considered implementing in my Ace Editor component, GraffitiSyntaxEditor.

1 Like

Once you embed a container, you cannot move it elsewhere. An instance of a containercontrol can only be embedded once.


Thank you for your response Tim,

By all indications, your statement appears accurate (and explicit).

The documentation for ContainerControl.EmbedWithinPanel on the other hand says the following:

An instance of a ContainerControl can only be embedded into one page.

Is it just me, or does the above seem less explicit? I read it to mean one page at a time.

Should I file a feedback request for further clarification? Or am I being too pedantic?

Thank you again.

Hmmm, I would have read that as referring to an action (the act of embedding) as opposed to a state (how many pages can a CC be within at a time). To mean the second, change into into in.

1 Like

I have marked the post by @Tim_Hare as the solution, because it comes the closest to answering my original question “Is it possible to keep an embedded ContainerControl from closing [after calling PagePanel.RemovePanelAt]?”

Tim’s statement appears to be true as far as I can tell.

Sorry it took so long to get back to experimenting with this more, but I needed some time off from my project after having my brain boiled during that unprecedented heat wave here in BC (we have no a/c in our house).

Thank you everyone for your comments and suggestions. I am slowly moving ahead with my workaround and recreating the ContainerControl instance. So far, so good.