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 a COM object

Status
Not open for further replies.

Ritter63

Programmer
Joined
Jun 8, 2005
Messages
1
Location
NL
Hi,

I need to copy a COM object. This COM object is a sourceless third party dll.

The problem that I am having is that all objects of this sort (table of contents object) should be stored in an ArrayList for later modification. The problem is however that when I use the elements in the ArrayList they are all the same. My conclusion was that all ArrayList contains is the last reference past to it and not true copies.

Is there a way to resolve this problem to the ArrayList can contain different table of contents objects. I'll have to do it without changing the code of the COM dll.

Kind regards,

Ritter63
 
The ArrayList might not be responsible. Just to make sure it's not the DLL that stores its data in static fields, have you tried to run your app twice and see if changes in one app affect the other one? Just a shot in the dark...

Volker/
 
I've noticed that ArrayLists (Like a lot of things in C#) hold a pointer, not a copy of the object.

When I write my classes, I also include a CloneMe() method to create a deep copy of the object.

public MyClass CloneMe()
{
MyClass temp = new MyClass();

temp.HouseNumber = this.HouseNumber;
temp.Street = this.Street;

return temp;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top