Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Release, AutoRelease

The Release Method lets you get rid of forms and form sets in an OOP way without needing to know the name of the variable that references the thing. AutoRelease determines whether a form set gets released when all its forms are gone.

Usage

oObject.Release()
frsFormSet.AutoRelease = lLetItGo
lLetItGo = frsFormSet.AutoRelease

Release exists because you need a way to shut down a form (or form set) when the user presses the OK (or Cancel or Close or whatever) button. Just put ThisForm.Release() in the Click method and you’re set. This method of shutting down a form does not fire the form’s QueryUnload method, so you may want to call QueryUnload explicitly and issue Release only if QueryUnload returns .T.

It’s possible to CLOSE ALL the forms in a form set and still have the form set object hanging around in memory. AutoRelease lets you change that. If you set it to .T., the form set is released as soon as its last form member is gone. However, form sets created in the Form Designer are always released when their last form goes away, regardless of the setting of AutoRelease. Only form sets created as objects (using CREATEOBJECT() or NewObject()) can cling to life when they’re empty.

Take a look at the example for ON SHUTDOWN for one approach to using Release.

Example

* Put this in a Close button's Click method.
ThisForm.Release()

See Also

Destroy, On Shutdown, QueryUnload, ReleaseType, Unload