Ah - you want cloning! I wrote a longish note about this in this forum some time ago. Unfortunately, the search engine does not appear to working properly at the moment, so I can't find the necessary link.
In summary, effective cloning of COM objects is tricky, even though it sounds like it should be easy. But there are lots of complications (e.g what if the object contains a reference to another object: do you need to clone that referenced object as well? Or, a simpler example, what if the object contains a handle to a bitmap: will you need to make a copy of that bitmap and return thus generate a new handle?)
Anyway, as a result VB has no general Clone method, although there are one or two objects that DO have a Clone method, eg the Font object (if you use the IFont interface). Additionally, some objects are what is know as self-persisting (eg the Picture object), which means that you can clone them via writing to and then reading from a PropertyBag)
In general, however, you'd have to write your own cloning method. A generic cloning method would require you to be able to enumerate all the properties of the current object, identify their current value, and then write them to the properties of a new, empty object. Of course, even this has problems: some of the properties of an object might be Get but not Let - so how would you write them?
Just for fun, here's the ProertyBag nmethod of cloning a Picture: [tt]
Public Function ClonePicture(srcPicture As Picture) As Picture
With New PropertyBag
.WriteProperty "temp", srcPicture
Set ClonePicture = .ReadProperty("temp"
End With
End Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.