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.

Was it helpful?

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

OTHER TIPS

try this

with Screen do
     for I := FormCount - 1 downto 0 do
       if Forms[I] <> Application.MainForm then
           Forms[I].Close;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top