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 ?
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?
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”
[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.
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.