List Info

Thread: Re: Closing and freeing a form from itself




Re: Closing and freeing a form from itself
country flaguser name
United States
2007-03-30 11:13:25

I actually do this all the time - the only form that is created when I
start the app is the main form and the data form. However, it does
not help when the form is shown non-modally, since you must leave the
function without freeing the popped form.

Thanks anyway.

I anyone doing this for non-modal forms?
jamie

--- In delphi-en%40yahoogroups.com">delphi-enyahoogroups.com, Samuel Luján Navarro <slujan7e...>
wrote:
&gt;
>
> Hi Jamie:
&gt;
> I do something like this, but with modal forms.
&gt;
>
>
> You can create a class function or a class procedure:
>
> .
>
> .
>
> .
>
> public
&gt;
> { Public declarations }
>
> class function FunctionName(parameters ):type;
>
> .
>
> .
>
> .
>
>
>
> Next in the implementation section ...
>
>
> *implementation*
&gt;
>
>
> {$R *.dfm}
&gt;
>
>
> class function TFormName.FunctionName(parameters ...):type;
>
> Var ...
>
> begin
&gt;
> with Create(Application) do
>
> try
>
> ... // your sentences here
>;
> Showmodal;
>
> ...
>
> finally
>
> Free;
&gt;
> end;
>;
>
>
> You can call this Function from any other form ...
>
>
>
> TFormName.FunctionNAme(parameters ...);
&gt;
>
>
>
>
> Don't forget to put the name of class function or class procedure in
the
> uses section.
>
>
>
> Regards,
>
> Sami,
&gt;
>
> Jamie L. Mitchell escribió:
> >
>; > Hello all:
>; >
>; > I remember seeing a tip from ... somewhere on this issue. I cannot
&gt; > seem to dig it up now.
>; >
>; > I would like to have a global variable for a form:
&gt; >
>; > frmGlobal: TfrmGlobal;
> >
>; > I would like to instantiate it from any place:
&gt; >
>; > frmGlobal := TfrmGlobal.Create(Application);
> >
>; > and show it as a non-modal form:
&gt; >
>; > 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
&gt; > merely freeing the variable does not set it to NIL, the system thinks
&gt; > it is still there.
&gt; >
>; > 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
&gt; > this (chicken or egg problem.) A lot of AV's come out of
> > experimenting with this.
&gt; >
>; > Does anyone have a good solution to how to free and NIL [the global
&gt; > variable] form from inside itself?
> >
>; > Thanks
&gt; > jamie
&gt; >
>; >
>
>
>
> [Non-text portions of this message have been removed]
>

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )