Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy of an object without reference?

Status
Not open for further replies.

patrickdrd

Programmer
Nov 21, 2003
149
GR
Hi everyone!

I need to get a copy of an object,
I do not want Set obj2 = obj1 because the new obj2
contains the reference of obj1 and changes are reflected to obj1.

I do not want to have the changes reflected to obj1.

Thanks in advance!
 
Is it a control object. An control object can be "Load"-ed in reference to the original object (obj1) with out reflecting the changes to the original object (obj1). Otherwise if the object is com compliant (activex) you should be able dim Obj2 as New My.Object. Get it? I don't know if this helps but if you had some more specific information we may be able to help you.

thanks
Scoty ::)
 
Could you not
Set Obj2 = New Obj1
This would produce a new Object rather than a reference to the original object.

 
Ok
How 'bout

Set Obj2 = New Obj1

Obj2.Property1 = Obj1.Property1
Obj2.Property2 = Obj1.Property2
Obj2.Property3 = Obj1.Property3
...

I know it seems kind of low brow programming but it will work.


 
Actually the object I'm referring to is a collection
 
So what about
Dim I as Long
Set Obj2 = New Obj1
For I = 0 to Obj1.Count - 1 '0 Based
Obj2.Item(I) = Obj1.Item(I)
Next I

Am I missing something?
 
Maybe you could get jiggy with RtlMoveMemory and ObjPtr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top