Bryan Carbonnell
carbonnb at sympatico.ca
Fri Apr 18 09:55:58 CDT 2003
On 18 Apr 2003 at 9:07, Brett Barabash wrote: > Here's one that is stumping me: > I want to write an ActiveX DLL that contains: > - A class module to handle all properties/methods/events. > - A form that is instantiated by the class, to display visual > information to the user. > > The form needs to interact with the class module to get at its > properties/methods/events, so I thought that I should store an object > reference in the form. I tried the following code in the form: > > Private WithEvents mobjSrcObj As clsMyClass > > Public Property Set SourceObject (objSrcObj As clsMyClass) > Set mobjSrcObj = objSrcObj > End Property > > In the class module, I have the following code: > > Private mfrmMyForm As frmMyForm > > Public Sub Class_Initialize > Set mfrmMyForm = New frmMyForm > Set mfrmMyForm.SourceObject = Me > End Sub > > This works great, except for one small thing. I cannot destroy the > class instance by setting it to Nothing, because the Form it > instantiated still has a reference to it. > > There has to be a simple solution to this! It sounds like you will need a "Tear Down" method of your class. In your calss add: Public Sub TearDown () Set mfrmMyForm.SourceObject = Nothing Set mfrmMyForm = Nothing End Sub Then when you want to destroy the class you need to call your TearDown method before you set it to nothing 'Close and destroy YourClassVariable.TearDown Set YourClassVariable = Nothing It's the same approach you have to take when you build Parent Properties for Classes. -- Bryan Carbonnell - carbonnb at sympatico.ca Age is a very high price to pay for maturity.