Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing any windows automatically 3

Status
Not open for further replies.

Papy33

Technical User
Dec 2, 2002
1
FR
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 !

Papy33
 
Hi, papy33

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 &quot;TimerCloseForms&quot;)

//****
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

greetings from |+|

Stefan
 
Suggest slight enhancement to Stefan'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 &quot;if(idx<Screen.FormCount)&quot; safeguard.

Have fun
Simon

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top