unit Unit4;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
Type
TFreeObjList =
Class (TStringList)
destructor Destroy;
override;
end;
TMyOwnObject =
class
protected
private
Myfrm : TForm;
function CheckA : boolean;
public
a : SmallInt;
b : Double;
c : TDateTime;
d : AnsiString;
e :
String[40];
ObjInternList : TFreeObjList;
function CheckB : Boolean;
constructor Create;
destructor Destroy;
override;
end;
type
TForm4 =
class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
tmpObject : TMyOwnObject;
MyObjList : TFreeObjList;
public
{ Public-Deklarationen }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
{---------------------------------------------------------------------------}
{------------ TFreeObjList- Stringliste mit Freigabe aller Objekte ---------}
{---------------------------------------------------------------------------}
destructor TFreeObjList.Destroy;
Var
i : Integer;
TmpObj : TObject;
begin
for i:=0
to Count-1
do
begin
TmpObj := Objects[i];
if Assigned(TmpObj)
then
FreeAndNil(TmpObj);
end;
Inherited Destroy;
end;
{---------------------------------------------------------------------------}
{ TMyOwnObject }
{---------------------------------------------------------------------------}
function TMyOwnObject.CheckA: boolean;
begin
Result := A <> 0;
end;
{---------------------------------------------------------------------------}
function TMyOwnObject.CheckB: Boolean;
begin
Result := B <> 0.0;
end;
{---------------------------------------------------------------------------}
constructor TMyOwnObject.Create;
begin
Myfrm := TForm.Create(Application);
ObjInternList := TFreeObjList.Create;
a := 1;
b := 2;
c := Now;
d := '
Hello';
e := '
World';
end;
{---------------------------------------------------------------------------}
destructor TMyOwnObject.Destroy;
begin
ObjInternList.Free;
if Assigned(ObjInternList)
then
Sleep(0);
inherited;
end;
{---------------------------------------------------------------------------}
procedure TForm4.FormCreate(Sender: TObject);
begin
MyObjList := TFreeObjList.Create;
end;
{---------------------------------------------------------------------------}
procedure TForm4.FormDestroy(Sender: TObject);
var
i : Integer;
aObj : TMyOwnObject;
begin
MyObjList.Free;
if Assigned(tmpObject)
then
begin
if tmpObject.CheckA
then
Sleep(0);
if Assigned(tmpObject.ObjInternList)
then
Sleep(0);
end;
if Assigned(MyObjList)
then
begin
for i := 0
to MyObjList.Count - 1
do
begin
aObj := MyObjList.Objects[i]
as TMyOwnObject;
if Assigned(aObj)
then
begin
if aObj.CheckA
then
Sleep(0);
if aObj.CheckB
then
Sleep(0);
end;
end;
end;
end;
{---------------------------------------------------------------------------}
procedure TForm4.Button1Click(Sender: TObject);
var
aObj : TMyOwnObject;
begin
if Assigned(MyObjList)
then
begin
aObj := TMyOwnObject.Create;
MyObjList.AddObject(TimeToStr(aObj.c), aObj);
end;
end;
{---------------------------------------------------------------------------}
procedure TForm4.Button2Click(Sender: TObject);
begin
if Assigned(MyObjList)
and (MyObjList.Count > 0)
then
begin
tmpObject := MyObjList.Objects[0]
as TMyOwnObject;
if Assigned(tmpObject)
then
Sleep(0);
end;
end;
{---------------------------------------------------------------------------}
end.