Board index » delphi » Need a special SHOW method

Need a special SHOW method

Hi everybody.
I have a problem: I need to make an application which uses many forms,
and it's necessary to create, show and then destroy them when they are
no longer needed. Well, this process would be simple if I could use the
Create->ShowModal->Destroy sequence, but I can't use the ShowModal
function. I need to make this sequence using the standard SHOW method.
This is my problem: if I write a Create->Show->Destroy sequence, the
Form is created and destroyed before I can see it. It doesn't wait, it's
destroyed immediately. However, I can't associate the form destruction
to a button (like exit), because a form can't be destroyed by its owned

Does someone know how can I implement a "delayed" Destroy method, which
is called from some events?

Thanx to everybody.

Diego Zanella


Re:Need a special SHOW method

What you need to do is use the Close Action in the onClose event. In there
enter the line
  Action := caFree;

This way you can create and show the form, and it will be freed
automatically when it is closed.

Re:Need a special SHOW method

In article <>, Diego Zanella wrote:
> Does someone know how can I implement a "delayed" Destroy method, which
> is called from some events?


no need to build something yourself, it is already build in. Add a handler
to the OnClose event of these non-modal forms. In the handler, set the
Action parameter to caFree. This way the form will destroy itself when the
user closes it. The default for Action is caHide, so normally the form
would not be destroyed (this feature is to support autocreated forms).

Peter Below (TeamB)

Re:Need a special SHOW method


>if I write a Create->Show->Destroy sequence

Depending on your needs you could arrange your forms to destroy
themselves when closing. In that case you just Create, Show and
forget. The destruction is automatic when closing.

To do that you attach a handler to the OnClose-Event and set
CloseAction to caFree in it. Just make sure you do not reference the
form after that.

If you ONLY use the Delphi-created reference (the "var
Form1:TForm1"-variable it puts into the unit for you), you can NIL
that as an additional measure.

  procedure TForm1.FormClose(Sender:TObject;
                             var CloseAction:TCloseAction);
      Form1:=NIL; { steal the reference }

If not use that reference you will have to think of another way to
check whether the form exists or not before accessing it. You could
for instance look it up in Screen.Forms (or was it Application.Forms)
by Classname, or Caption.

>Does someone know how can I implement a "delayed" Destroy method, which
>is called from some events?

I do not understand that question. If you have a reference to the form
you can Destroy it using that reference from anywhere like:


Ciao, MM

Marian Maier, Gamma Soft, Hainstra?e 8, 53121 Bonn, Germany
Tel: +49 228 624013 Fax: +49 228 624031
"Was schiefgehen kann geht schief"

Other Threads