I’ve got this MustInherit class called ViewerElement, from which derive classes like ViewerLine, ViewerImage, etc.
Then, in the main program I have a collection of different elements (Images, Lines, etc.). What I want to do is something like the following:
Dim NewElement As ViewerElement
For Each Element As ViewerElement In Elements
If blabla Then
NewElement = Element.Clone()
Exit For
End If
Next
Elements.Add(NewElement)
I’m getting desperate to implement this Clone method without getting errors. How should this be de done?
Thanks a lot in advance.
You should make
ViewerElementimplementIClonableinterface.Then, in
Clone()method you should create a newViewerElementobject copying all properties values (or changing them according to your needs).Clone()method must return an object that can be casted with your type; then it’s up to to you decide which values assume properties, wchis status has every single internal variable.An example (written in C#)