Difference between revisions of "Testing, if form exists/de"

From Lazarus wiki
Jump to navigationJump to search
m
m (Fixed syntax highlighting; deleted category included in page template)
 
Line 6: Line 6:
  
 
Der einfachste Weg ist:
 
Der einfachste Weg ist:
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
if (MyForm = nil) then Application.CreateForm(TMyForm, MyForm);
 
if (MyForm = nil) then Application.CreateForm(TMyForm, MyForm);
 
MyForm.Show;                             
 
MyForm.Show;                             
Line 13: Line 13:
 
Verwenden Sie Closeaction: = caFree in OnClose-Ereignis des Formulars z.B so:
 
Verwenden Sie Closeaction: = caFree in OnClose-Ereignis des Formulars z.B so:
  
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
procedure TMyForm.Formclose(Sender: Tobject; var Closeaction: Tcloseaction);
 
procedure TMyForm.Formclose(Sender: Tobject; var Closeaction: Tcloseaction);
 
begin
 
begin
Line 20: Line 20:
 
End;
 
End;
 
</syntaxhighlight>
 
</syntaxhighlight>
 
{{AutoCategory}}
 

Latest revision as of 10:10, 29 February 2020

Deutsch (de) English (en) français (fr)

Manchmal kann eine Form von mehreren Stellen in einem Programm gestartet werden. Wenn sie bereits vorhanden ist, muss sie nur nach vorn gebracht werden. Wenn nicht, muss sie erstellt werden.

Diese Methode wird nur benötigt, wenn die Form nicht automatisch erstellt wird (es sollte aber unter Hauptmenü -> Projekt -> Formulare zu finden sein).

Der einfachste Weg ist:

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

Verwenden Sie Closeaction: = caFree in OnClose-Ereignis des Formulars z.B so:

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