was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

48 Visitors Online


 
...vor dem dynamischen erzeugen einer Form überprüfen, ob sie schon existiert?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (26):  
     


{
  Q: How to know whether a form already exist before I dynamically create it ?

  A: See the Forms and FormCount property of TScreen. You can iterate
     through the forms, and test to see if your form is there.
}

function IsFormOpen(const FormName : string): Boolean;
var
  
i: Integer;
begin
  
Result := False;
  for i := Screen.FormCount - 1 DownTo do
    if 
(Screen.Forms[i].Name = FormName) then
    begin
      
Result := True;
      Break;
    end;
end;

// Example: Showing a TForm.
// First check, if the Form (here Form2) is open. If not, create it.

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not 
IsFormOpen('Form2') then
    
Form2 := TForm2.Create(Self);

  Form2.Show
end;

{ For MDI Children }

function IsMDIChildOpen(const AFormName: TForm; const AMDIChildName : string): Boolean;
var
  
i: Integer;
begin
  
Result := False;
  for i := Pred(AFormName.MDIChildCount) DownTo do
    if 
(AFormName.MDIChildren[i].Name = AMDIChildName) then
    begin
      
Result := True;
      Break;
    end;
end;

// Example: Showing a MDI Child.
// First check, if the MDI Child is open. If not, create it.

procedure TForm1.Button2Click(Sender: TObject);
begin
   if not 
IsMDIChildOpen(Form1, 'MyMDIChild') then
    
MyMDIChild := TMyMDIChild.Create(Self);

  MyMDIChild.Show;
  MyMDIChild.BringToFront;
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners