clone a containercontrol ?

All standard controls can be cloned if they are part of a control set.

You can instantiate as many instances of a Container Control as you want. They cannot made part of a Control Set, but they can very well be a part of an array.

If you want to clone controls with their content, then you have to devise your own cloning method that instantiates first the clone, and then copies values.

It is not very difficult to come up with.

You can even have a generalized clone method that uses a variant as parameter, and then with the help of introspection, does what is required according to the nature of the object : regular control or Container Control. It can even display an alert when the control is not in a Control Set.

I have a main superclass preferencecontainercontrol, and subclasses in each app I made
for example preferencebackupcc, preferencedblocationcc, preferenceusersignaturecc, etc.
they all are child of the preferencecontainercontrol.
I instanciate each prfrence needed in each application, but I instanciate a child, never the superclass.

and if I want to deal with any child in any application (external methods) I don’t know what they are
even then, for each application there is a new child specific to that app.
so to make a method that works for any child, as they are containercontrols, is not easy.
and again I cannot clone them there because I don’t know what they are really.
I should use a class interface, and make a clone method in that class interface to do this.

Hello,
You can know what using introspection. Actually, i have finised to make a generic list whi can accept any containercontrol view linked to data, and i must recognize each one to set/get data to CC. I can inject any CC to list and call his own method by this approach.
G.

Create an empty method “MyMethod” or so in PreferenceContainerControl and override it in each subclass for its specific need.

Create an empty method called “Clone” in PreferenceContainerControl and override it in each subclass for its specific need.

@Eli Ott “Override it in subclass”
You are totally reason, it’s a very good approach for potential common method in child like “clone” in this case. :wink:

Unfortunately, it can’t be used for specific method not (want to) declared (for severals reasons) on parent class. For that, the override cannot be used, and invoke this method need to recognize the content control. For the moment, I don’t find any other way than ‘introspection’ to get the class name of the CC. But if somebody do that with other approach, it’s a very interesting to do how…

Such a method has to be in the super class. What you describe later with “specific method” belongs of course into one of the subclasses. You have a contradiction in saying “method that works for any child” and “specific method”.

If the methods of all subclasses share the same method signature, create it in the superclass and override the method in all subclasses. If you then need to know which class an instance is of, use IsA to determine the child class type – you do not need to use introspection.

again, I cannot use introspection because where the method is (in a superclass module) I don’t know what are the childs.
even if I get the name of the child with introspection, I don’t know how to clone them !
eli is right, the best way to do this is to make a “clone” method in the superclass and override it in the childs
but then I have to make a clone method for each child, and I wanted to have a generic clone method for a containercontrol.

By definition a superclass does not know anything about its children. If you try to do something child-specific in a superclass, you are doing it wrong.

No object-oriented programming language supports automatic cloning – automatic cloning is just not possible. You need to write all cloning methods yourself.

[quote=321360:@Jean-Yves Pochez]the best way to do this is to make a “clone” method in the superclass and override it in the childs
but then I have to make a clone method for each child[/quote]
That’s the correct way to do it.