When my application is not used for a definite time, login and correlated rights are disabled. (TTimer function ) . I would like to close all windows, except the main one. How could I do ?
Thanks a lot !
As a Swiss Delph-beginner I hope I understood your question.
But please mind OnClose-Events and its close action:
<<
procedure TfFormX.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;//caHide
end;
>>
// Here you just find and close each Screen's Form which is
the same as to close all Application's Forms.
(You seam to know how to manage the timer "TimerCloseForms"
//****
procedure TfMain.TimerCloseFormsTimer(Sender: TObject);
var idx: Integer;
begin
(Sender as TTimer).Enabled := False;//disable Timer-Event
for idx := 0 to Screen.FormCount - 1 do begin
if Screen.Forms[idx] <> Self then begin //Self = fMain
with Screen.Forms[idx] do begin
Close;
end;//with
end;//if not Self
end;//for all Forms
end;
//***
I hope this code section encludes your problem's solution
change:
for idx := 0 to Screen.FormCount - 1 do begin
to:
for idx := Screen.FormCount - 1 downto 0 do
if(idx<Screen.FormCount)then begin
Reason: as you close and thereby free forms, Screen.FormCount will reduce, hence need to work backwards. Furthermore, freeing one form might free another, hence the "if(idx<Screen.FormCount)" safeguard.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.