unit Form.MainForm;
interface
uses
System.Generics.Collections,
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.ExtCtrls;
type
TFoo =
class
private
FValue:
string;
public
property Value:
string read FValue
write FValue;
end;
TForm1 =
class( TForm )
Timer1: TTimer;
TimerEnabledCheckBox: TCheckBox;
FillCachedValuePropertyCheckBox: TCheckBox;
procedure TimerEnabledCheckBoxClick( Sender: TObject );
procedure Timer1Timer( Sender: TObject );
procedure FormShow( Sender: TObject );
procedure FormActivate( Sender: TObject );
procedure FillCachedValuePropertyCheckBoxClick( Sender: TObject );
private
FValue:
string;
FFooList: TObjectList<TFoo>;
function GenerateValue:
string;
function GetValue:
string;
procedure PresentValues;
public
procedure AfterConstruction;
override;
procedure BeforeDestruction;
override;
end;
var
Form1: TForm1;
implementation
uses
System.StrUtils;
{$R *.dfm}
{ TForm1 }
procedure TForm1.AfterConstruction;
begin
inherited;
FFooList := TObjectList<TFoo>.Create( True );
FValue := GenerateValue;
end;
procedure TForm1.BeforeDestruction;
begin
FreeAndNil( FFooList );
inherited;
end;
procedure TForm1.TimerEnabledCheckBoxClick( Sender: TObject );
begin
Timer1.Enabled := TimerEnabledCheckBox.Checked;
end;
procedure TForm1.FillCachedValuePropertyCheckBoxClick( Sender: TObject );
begin
FFooList.Clear;
PresentValues;
end;
procedure TForm1.FormActivate( Sender: TObject );
begin
PresentValues;
end;
procedure TForm1.FormShow( Sender: TObject );
begin
PresentValues;
end;
function TForm1.GenerateValue:
string;
begin
Result := DupeString( '
Test', 1000 );
end;
function TForm1.GetValue:
string;
begin
if FillCachedValuePropertyCheckBox.Checked
then
Result := FValue
else
Result := GenerateValue;
end;
procedure TForm1.PresentValues;
begin
TimerEnabledCheckBox.Checked := Timer1.Enabled;
TimerEnabledCheckBox.Caption :=
string.Format( '
FFooList.Count = %d', [ FFooList.Count ] );
end;
procedure TForm1.Timer1Timer( Sender: TObject );
var
LFoo: TFoo;
LIdx: Integer;
begin
for LIdx := 1
to 100
do
begin
LFoo := TFoo.Create;
try
LFoo.Value := GetValue;
FFooList.Add( LFoo );
LFoo :=
nil;
finally
LFoo.Free;
end;
end;
PresentValues;
end;
end.