Question

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.

Était-ce utile?

La solution 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...

Autres conseils

try this

with Screen do
     for I := FormCount - 1 downto 0 do
       if Forms[I] <> Application.MainForm then
           Forms[I].Close;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top