Einzelnen Beitrag anzeigen

hanspeter

Registriert seit: 26. Jul 2003
Ort: Leipzig
1.350 Beiträge
 
Delphi XE2 Professional
 
#4

Re: MDICild nicht 2 mal öffnen

  Alt 28. Okt 2006, 17:55
Zitat von Bob68:
Hallo zusammen,
ich stehe im Moment total im Wald.

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

Danke Bodo
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
  Mit Zitat antworten Zitat