Hi Naomi,
>How can I use this class for my existing application where I suspect dangling references?
It's less about using the class, more about incorporating its ideas into your own base classes. OK, let's break this into only a few modules... Add the following methods to your base classes:
- Release
- Cleanup
- DoCleanup
- DoClearReferences
and the following property:
- lCleanedUp = .F.
In the Cleanup method set lCleanedUp to .T. For containers call the CleanUp method of all contained controls. Then call DoCleanUp, then DoClearReferences. For normal controls only call DoCleanup and DoClearReferences. In the Release method put:
This.CleanUp()
RELEASE This
In the RemoveObject method put:
LOCAL loRef
loRef = GETPEM(This,cName)
loRef.CleanUp()
loRef = NULL
DODEFAULT(This.cName)
And in the destroy event put:
ASSERT This.lCleanedUp
IF NOT This.lCleanedUp
THIS.CleanUp()
ENDIF
DoCleanUp() and DoClearReferences() are the two methods you use in sub classes. In DoClearReferences you place code that sets all object references in the object to NULL. In DoCleanUp put the code that disconnects the object from all other objects in a logical way, eg. deregister it from a manager class of some sort, and the like.
Now you should get an ASSERT message everytime you haven't properly cleaned up an object before VFP fired its Destroy event. Make sure you have SET ASSERTS ON to get notified. Your code to check object references would go into the CleanUp method after the DoClearReferences call.
--
Christof