Hello all:

I remember seeing a tip from ... somewhere on this issue.  I cannot
seem to dig it up now.

I would like to have a global variable for a form:

     frmGlobal: TfrmGlobal;

I would like to instantiate it from any place:

     frmGlobal := TfrmGlobal.Create(Application);

and show it as a non-modal form:

     frmGlobal.Show;

When I am done with the form, I would like to close it and free it up.
 Of course, the problem with this is that, at a later date, I may want
to  create it again.  To avoid a memory leak, I clearly would not want
to create a new instance if the existing instance still exists.  I
could use:

     If (Assigned(frmGlobal)) Then ...

except that assigned merely asks the variable, "are you NIL?"  Since
merely freeing the variable does not set it to NIL, the system thinks
it is still there.  

Since the form could be created anywhere, and the form should be
deleted when it is closed, the best way to deal with it would seem to
be figuring out a way to free the form and set the global variable to
NIL from the OnDestroy event.  I have had a number of problems doing
this (chicken or egg problem.)  A lot of AV's come out of
experimenting with this.

Does anyone have a good solution to how to free and NIL [the global
variable] form from inside itself?

Thanks
jamie


Reply via email to