Frage

Real life example: My application has a MainForm. The user can click on a button and login to see the modal AdminSettingsForm. From the AdminSettingsForm, he can open even more modal forms and so on.

When the user logs in to show the AdminSettingsForm, a timer is started, which should close the AdminSettingsForm after a period of inactivity (idleness).

I tried this:

 for i := Screen.FormCount - 1 downto 1 do begin
   if Screen.Forms[i] <> MainForm then begin
     Screen.Forms[i].Close();
   end;
 end;

Nothing happens until I close the topmost modal form, then everything else instantly closes.

War es hilfreich?

Lösung 2

I am sorry, but I think I already found a solution:

 Screen.ActiveForm.Close();

 for i := Screen.FormCount - 1 downto 1 do begin
   if Screen.Forms[i] <> MainForm then begin
     Screen.Forms[i].Close();
   end;
 end;

Seems to work...

Andere Tipps

try this

with Screen do
     for I := FormCount - 1 downto 0 do
       if Forms[I] <> Application.MainForm then
           Forms[I].Close;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top