unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,System.Contnrs, Unit2;
type
TMainForm = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
List: TComponentList;
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
procedure TMainForm.Button1Click(Sender: TObject);
Var
T : Tform;
begin
List.OwnsObjects:=True;
T:=TForm2.Create(Nil);
List.Add(T);
T.Show;
end;
procedure TMainForm.Button2Click(Sender: TObject);
var
Antal : Integer;
begin
Antal:=List.Count;
Memo1.Lines.Add('Forms Count '+IntToStr(Antal));
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
ReportMemoryLeaksOnShutdown:=True;
List:= TComponentList.Create;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
List.Free;
end;
end.
object MainForm: TMainForm
Left = 0
Top = 0
Caption = 'MainForm'
ClientHeight = 303
ClientWidth = 641
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 32
Top = 16
Width = 105
Height = 25
Caption = 'New Window'
TabOrder = 0
OnClick = Button1Click
end
object Memo1: TMemo
Left = 192
Top = 16
Width = 433
Height = 273
Lines.Strings = (
'Memo1')
TabOrder = 1
end
object Button2: TButton
Left = 32
Top = 55
Width = 105
Height = 25
Caption = 'Info'
TabOrder = 2
OnClick = Button2Click
end
end
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TSubForm = class(TForm)
Label1: TLabel;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
SubForm: TSubForm;
implementation
{$R *.dfm}
procedure TSubForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Hide;
Action := caFree;
end;
end.
object SubForm: TSubForm
Left = 0
Top = 0
Caption = 'SubForm'
ClientHeight = 299
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 120
Top = 48
Width = 60
Height = 13
Caption = 'Second form'
end
end
ASKER
ASKER
procedure TfrmList.ListFormsOfType(AObjectList: TObjectList; aClass: TClass);
Var
I: Integer;
begin
if AObjectList=Nil then begin
AObjectList:=TObjectList.Create;
AObjectList.OwnsObjects:=False;
end;
AObjectList.Clear;
for I := 0 to Screen.FormCount -1 do
Begin
if True then
if Screen.Forms[I] is aClass then Begin
AObjectList.Add(Screen.Forms[I]);
End;
End;
end;
Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.
TRUSTED BY
Open in new window
it should read
Open in new window
there is no point in maintaining your own Componentlist
the Screen has this property
after you have created TForm2, you can find it like this in the screen object
this routine frees all TForm2 type forms
Open in new window