Bernard,
If you want to create a new object from an existing object implement the
ICloneable interface in the object's class statement. Here is a class that
implements the ICloneable interface:
Public Class Insured
Implements ICloneable
Public Company As String
Public Name As String
Public Function Clone() as Object Implements ICloneable.Clone
' Create a new Insured object and set its property values equal to
those of the object instance upon
' which this method is called.
Dim insuredClone As New Insured()
insuredClone.Company = me.Company
insuredClone.Name = me.Name
Return insuredClone
End Function
End Class
-----------
' Example use.
Dim C1 As New Insured()
C1.Company = "Hartford"
' At this point one Insured object has been created in memory and C1
references (points to) it. The Company property of the object is "Hartford"
and its Name property is "" (empty).
Dim C2 As Insured = C1.Clone()
' At this point two Insured objects have been created in memory. The second
Insured method was created by calling the first object's Clone method and
assigning the resulting Insured object to the C2 variable. The first and
second object's Company property is "Hartford. The first and second
object's Name property is "" (empty)
C1.Name = "Tim"
C2.Name = "Bob"
' At this point C1 references the first Insured object created. Its Company
property is "Hartford"; its Name property is "Tim".
' C2 references the second Insured object created. Its Company property is
"Hartford"; its Name property is "Bob".
--
Mike
Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
"Bernard Bourée" <be*****@bouree.net> wrote in message
news:OJ**************@TK2MSFTNGP10.phx.gbl...
I have one object defined in a class called Class1
and these lines of code:
Dim C1 as New Class1
... some code to define the properties of C1
Dim C2 as New Class1
C2=C1
'Then some code to define C2.
BUT the lines of code to define the properties of C2 are changing the C1's
properties as well !!
What is wrong ?
Bernard