clone a containercontrol ?

Hi folks,

I have a window, with a listbox and a pagepanel in it, to mimic a preferences panels window.
in each panel, I have a container control embeded, that I assign at runtime, depending on the current user’s rights
the problem is, if I close the window, the cc are closed too, and I can’t re-embed them if the user reopens the window.
if I could make a clone of the cc before using it in the window it would be fine
but how to clone a cc ?

thanks.

When the window is closed and the containers are destroyed you should be able to re-use them when the window is opened again. Do you have an example project of it not working?

dim oPreferenceInstance as new ccPreference oPreferenceInstance.EmbedWithin(oPanel, 0, 0)

You can create a public property of the type of your container in your Application object or a module.
Then you can do something in your window’s open event like:

[code]if App.myContainer = nil then
App.myContainer = new MyCustomContainer
end

App.myContainer.EmbedWithin(self)[/code]

This way the container will not be destroyed when the window is closed, so you can re-embed the same container later.

I’m not sure this will work. When a window closes some properties of the controls lose their state, even if you hold a reference to the container, if I remember correctly.

But why do you want to keep a container control alive when the window closes?

The way I understood OP is that this is not what he’s trying to do.

It read like he was running into the EmbedWithin limitation “An instance of a ContainerControl can only be embedded into one object.”
http://documentation.xojo.com/index.php/ContainerControl.EmbedWithin

Looks like you’re right Eli, that was top of the head code and doesn’t appear to work as needed.

[quote=321164:@Tim Parnell]The way I understood OP is that this is not what he’s trying to do.

It read like he was running into the EmbedWithin limitation “An instance of a ContainerControl can only be embedded into one object.”
http://documentation.xojo.com/index.php/ContainerControl.EmbedWithin[/quote]
in fact the error I get is another one : “Cannot embed a closed ContainerControl”

I’m ok to kill the cc when the window closes, but if I re-open the window (remember it’s a pref window) I want to be able to re-embed the cc and I cannot as I have the error just above “Cannot embed a closed ContainerControl”

yes I already experimented this. you cannot use something that has been closed without using a “new” one

[quote=321158:@Tim Parnell]When the window is closed and the containers are destroyed you should be able to re-use them when the window is opened again. Do you have an example project of it not working?

dim oPreferenceInstance as new ccPreference oPreferenceInstance.EmbedWithin(oPanel, 0, 0)[/quote]
I do this in the open event of the application. but each app has his own preferences, and I want to make a generic method to deal with open-read-save-close the preferences window, at this point I cannot know what cc prefs are used in the window. I only know their superclass, but I don’t know each child.

well it seems a generic clone method for any object would be a nice feature request for xojo …

And what is the problem with creating a new one?

I don’t know which one it is I only have it’s suoerclass, not the class itself

Please create and share a sample project. I use containers religiously and have had no issues.

When you create it the first time, you know which class to instantiate. Why do you not know which class to instantiate the second time?

You’re relying too heavily on the view (containercontrol). You should be able to create and destroy it at will without affecting the underlying data. I agree with Eli, if you don’t know what kind of container to create, there’s something wrong with your design.

after a good night break, ideas become clearer and thanks to your posts, I redesigned the thing another way.
it’s working now.
but still a way to clone any object would be nice.

Cloning is a difficult subject. Shallow cloning? Deep cloning? If deep cloning, only the top level, or two levels, or all levels?

a clone for any rectcontrol first.

Again (no offense): Shallow cloning? Deep cloning? If deep cloning, only the top level, or two levels, or all levels?