Announcement

Collapse
No announcement yet.

verschiedene Formulare mit einem Klick schliessen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • verschiedene Formulare mit einem Klick schliessen

    Habe ein Programm, das 8 verschiedene Programme öffnet. nun das Problem: wenn ich alle Programme aufgemacht habe, muss ich alle einzeln schliessen. wie kann ich alle von der "Hauptseite " aus schliessen?

    Schon mal danke im Voraus.
    If it's there and you can see it – it's REAL
    If it's there and you can't see it – it's TRANSPARENT
    If it's not there and you can see it – it's VIRTUAL
    If it's not there and you can't see it – it's GONE!

  • #2
    Du erzeugst die Formulare ja in der Hauptseite? Lege Dir dort eine TList an und speichere die Formulare da rein (TList.Add). Dann kannst Du sie dort einfach wieder abrufen (TObject(MyList[i])), die Formulare freigeben (TObject(MyList[i].Free) und die Liste Leeren (TList.Clear).<p>
    Mari
    Schöne Grüße, Mario

    Comment


    • #3
      Hallo,

      wenn das Hauptformular Owner der Unterformulare ist, könnte es auch so gehen:

      for i := 0 to Componentcount - 1 do
      begin
      if components[i] is TForm then
      TForm(Components[i]).Close;
      end;

      Dafür müssten sie natürlich derselben Klasse angehören.

      Grüße

      Juli

      Comment


      • #4
        Die anderen Programme sind "externe ", eigenständige Programme, d.h., dass sie auch ohne die "Hauptseite" Funktionieren. Sie sind auch extra gespeichert.
        Ich habe zum Öffnen einfach den Pfad eingebaut.
        Könntet Ihr mir vielleicht den Quelltext Beschreiben; Ich bin nämlich (fast) absoluter Delphi-Neueinsteiger
        If it's there and you can see it – it's REAL
        If it's there and you can't see it – it's TRANSPARENT
        If it's not there and you can see it – it's VIRTUAL
        If it's not there and you can't see it – it's GONE!

        Comment


        • #5
          Das habe ich beim suchen gefunden:

          Ein Beispiel, wie man eine andere Anwendung aus dem eigenen Programm heraus beendet, findet man in der Unit CloseApp. Man braucht dazu das Instanzen-Handle der zu beendenden Anwendung.

          unit CloseApp;

          { By Duncan McNiven, [email protected] }
          { Comments by Brad Stowers, [email protected] }

          interface

          uses WinTypes;

          procedure CloseAppFromInst(HInst: THandle);

          implementation

          uses WinProcs, Messages;

          { Callback function that has each top-level window passed to it. }
          { Return true to continue enumerating, false to stop. }
          function EnumWindowsProc(Handle: HWND; Info: Pointer): boolean;
          {$IFDEF WIN32} stdcall; {$ELSE} export; {$ENDIF}
          begin
          Result := TRUE; { continue enumeration }
          { Does this app have the same instance as what we are looking for? }
          {$IFDEF WIN32}
          if GetWindowLong(Handle, GWL_HINSTANCE) = LongInt(Info) then begin
          {$ELSE}
          if GetWindowWord(Handle, GWW_HINSTANCE) = LongInt(Info) then begin
          {$ENDIF}
          PostMessage(Handle, WM_CLOSE, 0, 0); { Close the app }
          Result := FALSE; { stop enumerating windows, we are done. }
          end;
          end;

          procedure CloseAppFromInst(HInst: THandle);
          begin
          EnumWindows(@EnumWindowsProc, LongInt(HInst));
          end;

          end

          Comment

          Working...
          X