Reputation: 5808
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.
Upvotes: 1
Views: 2764
Reputation: 21
try this
with Screen do
for I := FormCount - 1 downto 0 do
if Forms[I] <> Application.MainForm then
Forms[I].Close;
Upvotes: 1
Reputation: 5808
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...
Upvotes: 0