Thread: Re: Closing and freeing a form from itself
Re: Closing and freeing a form from
itself
United States
2007-03-30 13:47:27
Damn! That is way clever by half. And it appears to work correctly.
Thanks!
jamie
--- In delphi-en%40yahoogroups.com">delphi-enyahoogroups.com, "Martin Wynne" <groups...> wrote:
>
> > Having freed the form, the control is no
> > longer there to finish up. That has always
> > been the problem that I have run into.
>
> Change the form's Tag property in the Close button event.
>
> Read the Tag in the application's OnIdle event, and free
> the form there.
>
> Martin. >
The below procedure code considers
1. "form1" is the default global variable created by Delphi in the
unit.
2. There is always only one instance of form1 created at any time.
//------------------------
procedure Tform1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree; form1 := nil;
end;
//-------------------------
To call this from another form (say, a Main Form)
//-------------------------
procedure TMainForm.Button1Click(Sender: TObject);
begin
if form1 = nil then
form1 := Tform1.Create(Application); form1.Show;
end; //-------------------------
HTH,
Vishak
---------------------------------------------------------- --- In delphi-en%40yahoogroups.com">delphi-enyahoogroups.com, "Jamie L. Mitchell" <jamiemi...>
wrote:
>
> Damn! That is way clever by half. And it appears to work
correctly.
>
> Thanks! >
> jamie
>
> --- In delphi-en%40yahoogroups.com">delphi-enyahoogroups.com, "Martin Wynne" <groups> wrote:
> >
> > > Having freed the form, the control is no
> > > longer there to finish up. That has always
> > > been the problem that I have run into.
> >
> > Change the form's Tag property in the Close button event.
> >
> > Read the Tag in the application's OnIdle event, and free
> > the form there.
> >
> > Martin. > >
>