-
Mar 15th, 2017, 02:57 PM
#1
Thread Starter
Hyperactive Member
Create a copy of an Object
Hello,
I want to create an exact copy (clone) of a class instance ( not reference). This original class also contains instances of other classes.
I looked on this forum and it has been said there is no way to do this.
Just want to make sure it is not possible to create an exact copy of an existing class instance?
thanks
-
Mar 15th, 2017, 03:26 PM
#2
Re: Create a copy of an Object
There is no way to replicate objects globally, without knowing the intrinsic object logic.
Suppose that the object has two properties variables with references to other objects:
Public MainForm as Form
Public WordInstance as Object
What should the replicator do?
1) Load a new instance of MainForm and open another WordInstance?
2) Just set a new reference to the same MainForm and WordInstance objects already opened?
There is no way to know.
So, the usual way is that each object needs to provide a Clone method, and replicate itself:
Public Function Clone() as MyObjectType
Dim VarMyObjectType as MyObjectType
Set VarMyObjectType = New MyObjectType
' copy all the variables properly
' If the object has other objects inside, they also must provide a Clone method
Set Clone = VarMyObjectType
End Sub
-
Mar 15th, 2017, 10:59 PM
#3
Re: Create a copy of an Object
Agree with Eduardo. You can only write Copy/Clone functions manually.
-
Nov 1st, 2021, 07:33 PM
#4
Junior Member
Re: Create a copy of an Object
I just posted a way, not sure it would suit the nesting, however, there is a scheme to memory address by pointers for objects called VTable, that you could possibly go through and check for global flags and handles. This example might be XP only, the online API reference says XP minimum for clients and Server 2003 for server.
https://www.vbforums.com/showthread....ects-In-Memory
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|