Sign in Join
Wiki copytemporary

Revision 1 of 1, by Trev on 2-29-2020. The page as it is now.

Testing, if form exists

Sometimes a form may be launched from several places in a program. If it already exists, it only needs to be brought to the front. If not, it needs to be created.

This method is only needed if the form is not auto created (ie not listed under Project|Project Options|Forms|Available forms).

The easiest way is:

pascal
if (MyForm = nil) then Application.CreateForm(TMyForm, MyForm);
    MyForm.Show;

Use CloseAction := caFree in the form's OnClose event, like so:

pascal
procedure TMyForm.FormClose(Sender: Tobject; var Closeaction: Tcloseaction);
    begin
      CloseAction := caFree;
      MyForm := nil;
    End;

This method is taken from forum discussions.

Warning-icon.png

Warning: This method has some limitations:


From the Free Pascal wiki, page "Testing, if form exists", as the Internet Archive kept it on 2024-12-06, last changed on 2020-02-29. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.