Difference between revisions of "Testing, if form exists"
From Free Pascal wiki
Jump to navigationJump to searchWindsurferme (talk | contribs) m |
Windsurferme (talk | contribs) |
||
Line 1: | Line 1: | ||
− | 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. | + | 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. (It will be listed under Project|Project Options|Forms|Available forms.) | |
− | + | The easiest way is: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight> | <syntaxhighlight> | ||
− | if | + | if MyForm <> nil then MyForm.Show |
else | else | ||
begin | begin | ||
Line 32: | Line 15: | ||
Use CloseAction := caFree in the form's OnClose event. | Use CloseAction := caFree in the form's OnClose event. | ||
+ | |||
+ | This method is taken from forum discussions. | ||
[[Category:Code]] | [[Category:Code]] | ||
[[Category:LCL]] | [[Category:LCL]] | ||
[[Category:Forms]] | [[Category:Forms]] |
Revision as of 08:37, 23 November 2013
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. (It will be listed under Project|Project Options|Forms|Available forms.)
The easiest way is:
if MyForm <> nil then MyForm.Show
else
begin
MyForm := TMyForm.Create(Application);
MyForm.Show;
end;
Use CloseAction := caFree in the form's OnClose event.
This method is taken from forum discussions.