unit Unit1;
interface
uses
Classes,
Contnrs;
type
TField =
class(TObject)
private
FName:
String;
FValue:
String;
public
constructor Create;
destructor Destroy;
override;
property Name:
String read FName
write FName;
property Value:
String read FValue
write FValue;
end;
{TField}
TFields =
class(TObject)
private
FInnerList: TList;
function GetItem(
Index: Integer): TField;
procedure SetItem(
Index: Integer; Item: TField);
function GetCount: Integer;
public
constructor Create;
destructor Destroy;
override;
function Add(Item: TField): Integer;
procedure Clear;
procedure Delete(
Index: Integer);
property Count: Integer
read GetCount;
property Items[
Index: Integer]: TField
read GetItem
write SetItem;
end;
{TFields}
TItemA =
class(TObject)
private
FName:
String;
FDesc:
String;
FFields: TFields;
public
constructor Create;
destructor Destroy;
override;
property Name:
String read FName
write FName;
property Desc:
String read FDesc
write FDesc;
property Fields: TFields
read FFields
write FFields;
end;
{TItemA}
TItemB =
class(TObject)
private
FName:
String;
FComment:
String;
FText:
String;
FFields: TFields;
FComp: TFields;
public
constructor Create;
destructor Destroy;
override;
property Name:
String read FName
write FName;
property Comment:
String read FComment
write FComment;
property Text:
String read FText
write FText;
property Fields: TFields
read FFields
write FFields;
property Comp: TFields
read FComp
write FComp;
end;
{TItemB}
TItems =
class(TObject)
private
FInnerList: TObjectList;
function GetData(
Index: Integer): TObject;
procedure SetData(
Index: Integer; Data: TObject);
function GetDataCount: Integer;
public
constructor Create;
destructor Destroy;
override;
function Add(Data: TObject): Integer;
procedure Clear;
procedure Delete(
Index: Integer);
property Count: Integer
read GetDataCount;
property Items[
Index: Integer]: TObject
read GetData
write SetData;
end;
{TItems}
implementation
uses
SysUtils;
{ TField }
constructor TField.Create;
begin
inherited;
//init
FName := EmptyStr;
FValue := EmptyStr;
end;
destructor TField.Destroy;
begin
//deinit
FValue := EmptyStr;
FName := EmptyStr;
inherited;
end;
{ TFields }
function TFields.Add(Item: TField): Integer;
begin
result := FInnerList.Add(Item);
end;
procedure TFields.Clear;
var
Idx: Integer;
begin
//deinit
if Assigned(FInnerList)
and (FInnerList.Count > 0)
then
begin
for Idx := 0
to FInnerList.Count - 1
do
begin
TObject(FInnerList.Items[Idx]).Free;
end;
{for}
end;
{if}
FInnerList.Clear;
end;
constructor TFields.Create;
begin
inherited;
//init
FInnerList := TList.Create;
end;
procedure TFields.Delete(
Index: Integer);
begin
//Objekt freigeben
TObject(FInnerList.Items[
Index]).Free;
//Eintrag löschen
FInnerList.Delete(
Index);
end;
destructor TFields.Destroy;
var
Idx: Integer;
begin
//deinit
if Assigned(FInnerList)
and (FInnerList.Count > 0)
then
begin
for Idx := 0
to FInnerList.Count - 1
do
begin
TObject(FInnerList.Items[Idx]).Free;
end;
{for}
end;
{if}
FInnerList.Free;
inherited;
end;
function TFields.GetCount: Integer;
begin
result := FInnerList.Count;
end;
function TFields.GetItem(
Index: Integer): TField;
begin
result := FInnerList.Items[
Index];
end;
procedure TFields.SetItem(
Index: Integer; Item: TField);
begin
if Assigned(Item)
then FInnerList.Items[
Index] := Item;
end;
{ TItems }
function TItems.Add(Data: TObject): Integer;
begin
result := FInnerList.Add(Data);
end;
procedure TItems.Clear;
var
Idx: Integer;
begin
//deinit
if Assigned(FInnerList)
and (FInnerList.Count > 0)
then
begin
for Idx := 0
to FInnerList.Count - 1
do
begin
TObject(FInnerList.Items[Idx]).Free;
end;
{for}
end;
{if}
FInnerList.Clear;
end;
constructor TItems.Create;
begin
inherited;
//init
FInnerList := TObjectList.Create;
end;
procedure TItems.Delete(
Index: Integer);
begin
//Objekt freigeben
TObject(FInnerList.Items[
Index]).Free;
//Eintrag löschen
FInnerList.Delete(
Index);
end;
destructor TItems.Destroy;
var
Idx: Integer;
begin
//deinit
if Assigned(FInnerList)
and (FInnerList.Count > 0)
then
begin
for Idx := 0
to FInnerList.Count - 1
do
begin
TObject(FInnerList.Items[Idx]).Free;
end;
{for}
end;
{if}
FInnerList.Free;
inherited;
end;
function TItems.GetData(
Index: Integer): TObject;
begin
result := FInnerList.Items[
Index];
end;
function TItems.GetDataCount: Integer;
begin
result := FInnerList.Count;
end;
procedure TItems.SetData(
Index: Integer; Data: TObject);
begin
if Assigned(Data)
then FInnerList.Items[
Index] := Data;
end;
{ TItemA }
constructor TItemA.Create;
begin
inherited;
//init
FName := EmptyStr;
FDesc := EmptyStr;
FFields := TFields.Create;
end;
destructor TItemA.Destroy;
begin
//deinit
FFields.Free;
FDesc := EmptyStr;
FName := EmptyStr;
inherited;
end;
{ TItemB }
constructor TItemB.Create;
begin
inherited;
//init
FName := EmptyStr;
FComment := EmptyStr;
FText := EmptyStr;
FFields := TFields.Create;
FComp := TFields.Create;
end;
destructor TItemB.Destroy;
begin
//deinit
FComp.Free;
FFields.Free;
FText := EmptyStr;
FComment := EmptyStr;
FName := EmptyStr;
inherited;
end;
end.