Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi MDICild nicht 2 mal öffnen (https://www.delphipraxis.net/79791-mdicild-nicht-2-mal-oeffnen.html)

Bob68 28. Okt 2006 12:58


MDICild nicht 2 mal öffnen
 
Hallo zusammen,
ich stehe im Moment total im Wald.

Ich öffne ein MDICHILD über ein MainMenu wie folgt.
Delphi-Quellcode:
TForm2.Create(self).
Ok das klappt auch, nun wie kann ich es verhindern das die Form ein zweitesmal aufgerufen wird??

Danke Bodo :wall:

dataspider 28. Okt 2006 13:47

Re: MDICild nicht 2 mal öffnen
 
Hi,

da gibt es verschiedene Ansätze.
Du könntes über Screen.Forms iterieren und prüfen, ob es ein Formular dieser Klasse oder mit dem Namen gibt.
Dann kannst du mit der Formularvariablen arbeiten.
Dazu musst du aber mit
Delphi-Quellcode:
if not Assigned(Form2) then
  Form2 := TForm2.Create(self);
das Formular öffnen und organisieren, dass beim Schliessen vom Form die Variable wieder auf nil gesetzt wird.

Cu, Frank

Bob68 28. Okt 2006 14:32

Re: MDICild nicht 2 mal öffnen
 
Hallo dataspider,
danke für deine schnelle Antwort.

Hab es hinbekommen.
Danke Bodo

hanspeter 28. Okt 2006 17:55

Re: MDICild nicht 2 mal öffnen
 
Zitat:

Zitat von Bob68
Hallo zusammen,
ich stehe im Moment total im Wald.

Ich öffne ein MDICHILD über ein MainMenu wie folgt.
Delphi-Quellcode:
TForm2.Create(self).
Ok das klappt auch, nun wie kann ich es verhindern das die Form ein zweitesmal aufgerufen wird??

Danke Bodo :wall:

Hallo,

ich habe das mal etwas komplizierter gelöst.
Ich rufe alle Forms mit einer Aufrufroutine auf und lege beim Aufruf fest, in welcher Art das Fenstergeöffnet werden soll.

Delphi-Quellcode:
Function ShowForm(aOwner : TComponent;
                  Form  : TFormClass;
                  Modus : TFormmodus;
                  TagId : Integer) : TForm;

Function GetMDIChild : TForm;
var i : Integer;
Begin
 result:=nil;
 if (Application.MainForm = nil) or (Application.MainForm.MDIchildcount = 0) then Exit;
  for i:=0 to Application.MainForm.MDIchildcount-1 do
      if Application.MainForm.MDIChildren[i].ClassName = Form.ClassName then
         Begin
          result:= Application.MainForm.MDIChildren[i];
          if result.WindowState = wsMinimized then result.Windowstate := wsnormal;
          Exit;
         end;
end;

Function FindMDIChild : TForm;
var i : Integer;
Begin
 result:=nil;
 if (Application.MainForm = nil) or (Application.MainForm.MDIchildcount = 0) then Exit;
  for i:=0 to Application.MainForm.MDIchildcount-1 do
      if (Application.MainForm.MDIChildren[i].ClassName = Form.ClassName)
        and (TagId = Application.MainForm.MDIChildren[i].Tag) then
         Begin
          result:= Application.MainForm.MDIChildren[i];
          if result.WindowState = wsMinimized then result.Windowstate := wsnormal;
          Exit;
         end;
end;

Begin
 result:=nil;
 Case Modus of
       fmMulti : Begin
                   result:= Form.Create(AOwner);
                   if result.Formstyle <> fsMDIChild then result.Formstyle:=fsMDIChild;
                  end;
       fmsingle : Begin
                   result:=GetMDIChild;
                   if result=nil then result:= Form.Create(AOwner);
                   if result.Formstyle <> fsMDIChild then result.Formstyle:=fsMDIChild;
                  end;
      fmsingleTag: Begin
                    result := FindMDIChild;
                    FormExists := result <> nil;
                    if (result = nil) then Begin
                                             result := Form.Create(AOwner);
                                             result.Tag := TagID;
                                            end;
                    if result.Formstyle <> fsMDIChild then result.Formstyle:=fsMDIChild;
                   end;            
      fmmodal  : begin
                   result:= Form.Create(AOwner);
                   result.visible:=false;
                   result.FormStyle:=fsnormal;
                   if result.Width > TForm(aOwner).ClientWidth-4 then result.left:=2
                       else result.Left:=(TForm(aOwner).ClientWidth-result.Width) shr 1;
                     if result.Height < TForm(aOwner).ClientHeight-4 then result.Top:= (TForm(aOwner).ClientHeight - result.Height) shr 1
                                                               else result.Top:=2;
                   result.ShowModal;
                   result.Free;
                   Result:=nil;
                   Exit;
                  end;
     fmnormal : begin
                   result:= Form.Create(AOwner);
                   result.visible:=false;
                   result.FormStyle:=fsnormal;
                   if result.Width > TForm(aOwner).ClientWidth-4 then result.left:=2
                       else result.Left:=(TForm(aOwner).ClientWidth-result.Width) shr 1;
                     if result.Height < TForm(aOwner).ClientHeight-4 then result.Top:= (TForm(aOwner).ClientHeight - result.Height) shr 1
                                                               else result.Top:=2;
                   Application.Processmessages;
                   Exit;
                  end;
    fmTop    : begin
                   result:= Form.Create(AOwner);
                   result.visible:=false;
                   result.FormStyle:=fsStayOnTop;
                   if result.Width > TForm(aOwner).ClientWidth-4 then result.left:=2
                       else result.Left:=(TForm(aOwner).ClientWidth-result.Width) shr 1;
                     if result.Height < TForm(aOwner).ClientHeight-4 then result.Top:= (TForm(aOwner).ClientHeight - result.Height) shr 1
                                                               else result.Top:=2;
                   Application.Processmessages;
                  end;
               end;

  if result <> nil then Begin
                         Application.Processmessages;
                         result.Show;
                        end;
end;
fmMulti - Beliebig oft als MDI öffnen

fmsingle - Nur einmal als MDI öffnen, bei erneuten aufruf Focus auf vorhandenes Fenster

fmsingleTag - Nur einmal pro Vorgang öffnen. z.B. jeweils für neue Kundenbearbeitung bei öffnen für bereits geöffneten Kunden nur Focus setzen

fmmodal - Öffnen als modales Fenster

fmnormal - Normal öffnen mit .Show.

fmTop - stay on Top

Gruß Peter


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:27 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz