How to get a list from all opened forms of my software?
Asked Answered
S

4

8

I want to ask the user to close all opened forms before terminate my application.

How can I automatically get a list from opened forms?

I'm using Delphi 2006, and don't using form's Auto-Create, but I'm using the auto created form's referenced var with Application.CreateForm.

My regards.

Sunstroke answered 23/9, 2011 at 13:36 Comment(0)
R
21

Have a look at Screen.FormCount and Screen.Forms.

Reld answered 23/9, 2011 at 13:43 Comment(1)
thx man, Screen.FormCount and Screen.Forms solves my problem!Sunstroke
L
3

A possible solution (I use in C#) is to store every opened form instance in a list var. For example you could have a global list named openedForms; when every form is created, form itself can add its reference to openedForms and remove it when closing.
When user tries to close your app, you could check that list count is greater than zero and, if user wants really close, you close gracefully every form instance contained in openedForms before shutting the app down.

Limnetic answered 23/9, 2011 at 13:40 Comment(0)
H
1
procedure ShowAllForms;
VAR i: Integer;
begin
  for i:= 0 to Screen.FormCount-1 DO
   ShowMessage(Screen.Forms[i].Name); 
end;

or if you want to show also the MDI forms:

procedure ShowAllForms;
var i:integer;
begin
  with Application do
   for i:=0 to componentcount-1 do
    if components[i] is TMyCustomForm          //your form class here, or simply TForm
    then ShowMessage(components[i].Name);
end;
Herzig answered 3/3, 2016 at 12:16 Comment(0)
T
0

I use

Main.MDIChildCount >0

for Child forms.

Touched answered 23/9, 2011 at 13:49 Comment(1)
Thx by answer, but I'm not using MDI.Sunstroke

© 2022 - 2024 — McMap. All rights reserved.