Beware with this method since I doubt that the GC of VFP will clean up the class when it is released because of the circular reference. I've done a quick test and you can see that the memory is not released:
clear
CLEAR all
? SYS(1016)
abc = NEWOBJECT("testme")
abc = null
? SYS(1016)
abc = NEWOBJECT("testme")
abc = null
? SYS(1016)
abc = NEWOBJECT("testme")
abc = null
? SYS(1016)
CLEAR all
? SYS(1016)
DEFINE CLASS testme as Custom
PROCEDURE init
this.addproperty ("self", this)
ENDPROC
ENDDEFINE
Put the Init of the class in comments and run the test again. You'll see that the memory is now cleared.
>I don't know of a way innate to VFP, but in the init, I like to add a property called self to my objects.
>
>This.AddProperty('Self', This)
>
>Then, of course, it's easy to send .self as a parameter withing a with...endwith.