Autor Beitrag
discmix
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Di 13.05.03 11:58 
Hallo,

ich habe eine MDI-Anwendung realisiert. Die MDI-Childs rufe ich erst zur Laufzeit über einen Knopfdruck:
ausblenden Quelltext
1:
2:
    Application.CreateForm(TForm3,FormKontakte);
    FormKontakte.Show;

auf. Wie kann ich aber nun verhindern das das MDIChild nun mehrfach angezeigt wird. D.H. wenn der Knopf noch einmal angeklickt wird, soll das Fenster wenn schon vorhanden den Focus erhalten.
Wie kann ich das realisieren?

Danke
DiscMix

Moderiert von user profile iconTino: Code-Tags hinzugefügt.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Di 13.05.03 13:11 
Warum machst Du dann eine MDI Anwendung?
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Di 13.05.03 13:24 
Hi,

deaktiviere doch den Button einfach nach dem du das Child-Fenster erzeugst (enabled := false). Wenn du es wieder schliesst kannst du den Button wieder auf enabled := True stellen.

MFG

- Ernesto -
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 13.05.03 15:05 
Tino hat folgendes geschrieben:

Warum machst Du dann eine MDI-Anwendung


Ich hab das Problem selber. Hab eine Anwendung, in der mehrere Fenster als MDI angezeigt werden, damit man sich die Übersicht selbst frei gestalten kann. Diese Fenster sollten aber aufgrund von Datenanbindungen nicht mehrfach geöffnet werden können. Kein Problem, wenn das Fenster beim Start erstellt wird. Aber wenn man das so macht, wie er, dann ist das schwieriger. Hab das erstmal mit einer Schleife durch MDIChilds gelöst, wo dann die Captions verglichen werden. Nicht ganz sauber, aber es funktioniet einigermaßen.

Und das mit dem Aktivieren ist auch nicht der Weisheit letzter Schluss, da beim Button-Klick es am besten wäre, wenn das Fenster dann in den Vordergrund geholt wird.

Wäre aber gut, wenn jmd eine bessere Idee hat. Mich interessiert das auch.
discmix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Di 13.05.03 18:28 
Danke für die Denkanstöße.

Ich habe jetzt einfach die Eigenschaft Tag der Form missbraucht.
Tag auf 1 bei Create und 0 bei Destroy. Nun kann ich's einfach abprüfen.
Dann funktioniert's sogar der Form den Focus zu geben.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TFormHaupt.Window_AnsprechpartnerExecute(Sender: TObject);
begin
    if Window_AnsprechPartner.Tag <> 1 then
    begin
        Application.CreateForm(TFormAPartner,FormAPartner);
        FormAPartner.Show;
        Window_AnsprechPartner.Tag :=1;
    end else FormAPartner.BringToFront;
end;


Beim Schliessen des MDIChild:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TFormKontakte.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    FormHaupt.Window_Kontakte.Tag:=0;
    Action:=caFree;
end;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 13.05.03 19:16 
Irgendwie is das ne klasse Idee, schade, dass ich da nicht drauf gekommen bin, danke ebenfalls *g*

Gruß
Taladan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 88


Delphi 2005 Personal
BeitragVerfasst: Sa 04.06.05 22:51 
Hallo. Lange ist dieser Posting her, aber genau das ist es was ich suche.

Ich erzeuge meine MDIChilds erst zur Laufzeit. Möchte aber verhindern, das ein zweites Child dieser Art erzeugt wird. Wie kann ich das bewerkstelligen?
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: So 05.06.05 06:04 
Die Lösung steht doch zwei Postings weiter oben oder etwa nicht? :gruebel:

_________________
JSXGraph
Taladan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 88


Delphi 2005 Personal
BeitragVerfasst: So 05.06.05 11:16 
weil ich genau an dieser stelle
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
    if NamenBox.Tag <> 1 then //hier
    begin
        Application.CreateForm(TNamenBox,NamenBox);
        NamenBox.Show;
        NamenBox.Tag :=1;
    end else NamenBox.BringToFront;


immer eine Fehlermeldung bekomme. Das liegt wohl daran, das NamenBox noch nicht existiert. Ich möchte verhindern das überhaupt erst zwei davon erzeugt werden!
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: So 05.06.05 11:55 
Dann musst du einfach noch eine Überprüfung vorneweg schalten, ob das NamenBox nil ist oder nicht. Ist es nil, dann wurde es noch nicht erzeugt, ist es nicht nil, wurde es bereits erzeugt und dein oben geposteter Code kann ausgeführt werden.

_________________
JSXGraph
Taladan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 88


Delphi 2005 Personal
BeitragVerfasst: So 05.06.05 12:23 
Nu hab ich das Problem, wenn ich NamenBox schließe (mit action := CaFree) und erneut öffnen will, klappt es nicht. hier mein code

ausblenden Delphi-Quelltext
1:
2:
3:
4:
    if NamenBox = nil then
    begin
            Application.CreateForm(TNamenBox,NamenBox);
    end else NamenBox.BringToFront;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TNamenBox.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;
Taladan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 88


Delphi 2005 Personal
BeitragVerfasst: So 05.06.05 12:55 
Fehler gefunden. :D

Der Aufruf:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TMainForm.Namen1Click(Sender: TObject);
begin
    if NamenBox = nil then
    begin
            NamenBox := TNamenBox.Create(Application);
            NamenBox.show;
    end else NamenBox.BringToFront;
end;


Das Fenster schließen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TNamenBox.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
  NamenBox := nil
end;


Find ich sogar ne bessere Variante als obrige über die TagNachprüfung :-)
illky
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Di 07.06.05 08:32 
Hi,

das sind alles gute Lösung und sollten auch genügen. Eine andere Lösung wäre alle MDI-Kinder zu durchlaufen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  Neu:=True;
  For i:=0 to MdichildCount-1 Do
  begin
    If (MDIChildren[i] is TFormklasse) Then
    Begin
      Neu:=True;
      (MDIChildren[i] as TFormklasse).BringToFront;
    end;
  end;
  If Neu then TFormklasse.CreateForm(Form, TFormklasse);


Solange man keine MDIs in DLL auslagern möchte sollte dies ganz gut gehen.
'Show' kann man sich bei MDIs sparen.

ciao
Stefan

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.