Testing, if form exists
Deutsch · English
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:
if (MyForm = nil) then Application.CreateForm(TMyForm, MyForm);
MyForm.Show;Use CloseAction := caFree in the form's OnClose event, like so:
procedure TMyForm.FormClose(Sender: Tobject; var Closeaction: Tcloseaction);
begin
CloseAction := caFree;
MyForm := nil;
End;This method is taken from forum discussions.
Warning: This method has some limitations:
- Not more than one instance of that form class should exist at any time.
- Reference to any created form of that class should be stored in a single global variable.
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.
Edited on wiki.freepascal.org by 9 people, 2013–2020
From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.
| When | Who | What changed |
|---|---|---|
| Windsurferme | Test that form exists, Find form | |
| Jwdietrich | Categories added. | |
| BigChimp | I think you meant forum discussions ;) Thanks for the page! | |
| HowardPC | (minor) | |
| Jwdietrich | moved test form exists to Testing, if form exists (minor) | |
| Windsurferme | (minor) | |
| Windsurferme | ||
| Windsurferme | ||
| Windsurferme | ||
| Windsurferme | ||
| Michl | ||
| Michl | ||
| Michl | ||
| Michl | ||
| Michl | ||
| FTurtle | ||
| E-ric | ||
| E-ric | ||
| Mai | (minor) | |
| Mai | (minor) | |
| Trev | Fixed syntax highlighting (minor) |
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
