Powerbasic Museum 2020-B

General Category => General Discussion => Topic started by: Chris Holbrook on December 31, 2012, 12:46:28 PM

Title: class method to add its interface to a collection
Post by: Chris Holbrook on December 31, 2012, 12:46:28 PM
I have a class containing a method which wants to store the current object (me) in a collection. It would be great to just say "myvariant = me", etc. But the compiler says no.

I can clone the current object by creating a new instance and copying each instance variable from the current object to it. But then I have effectively two definitions of the interface, one in the class declarations and the other in my cloning method, which is at the mercy of my coding and maintenance skills.

Is there an alternative way of grabbing the entire current object into a variant?


Title: Re: class method to add its interface to a collection
Post by: Stan Duraham on December 31, 2012, 01:00:09 PM
this might work


        Local o As IUnknown
        Local v As Variant
        o = Me
        v = o
Title: Re: class method to add its interface to a collection
Post by: Chris Holbrook on December 31, 2012, 01:12:37 PM
Thanks Stan, that works!