Aşağıdaki gibi class tanımlarım var. X ve Z li kopyaları neden oluşturduğumu aşağıda yazıcam.
Kod: Tümünü seç
TVariable_Attr = class
private
FName: String;
FValue: String;
public
property Name: String read FName write FName;
property Value: String read FValue write FValue;
end;
TVariable_Attr_List = TObjectList<TVariable_Attr>;
TVariable = class
private
FData_ID: Integer;
FVariable_Attr_List: TVariable_Attr_List;
public
property Data_ID: Integer read FData_ID write FData_ID;
property Variable_Attr_List: TVariable_Attr_List
read FVariable_Attr_List write FVariable_Attr_List;
constructor Create;
destructor Destroy; override;
end;
TVariable_List = TObjectList<TVariable>;
TVariable_Attrx = class
private
FName: String;
FValue: String;
public
property Name: String read FName write FName;
property Value: String read FValue write FValue;
end;
TVariable_Attrx_List = TObjectList<TVariable_Attrx>;
TVariablex = class
private
FData_ID: Integer;
FVariable_Attr_List: TVariable_Attrx_List;
public
property Data_ID: Integer read FData_ID write FData_ID;
property Variable_Attr_List: TVariable_Attrx_List read FVariable_Attr_List write FVariable_Attr_List;
constructor Create;
destructor Destroy; override;
end;
TVariable_Listx = TObjectList<TVariablex>;
TVariable_Attrz = class
private
FName: String;
FValue: String;
public
property Name: String read FName write FName;
property Value: String read FValue write FValue;
end;
TVariable_Attrz_List = TObjectList<TVariable_Attrz>;
TVariablez = class
private
FData_ID: Integer;
FVariable_Attr_List: TVariable_Attrz_List;
public
property Data_ID: Integer read FData_ID write FData_ID;
property Variable_Attr_List: TVariable_Attrz_List read FVariable_Attr_List write FVariable_Attr_List;
constructor Create;
destructor Destroy; override;
end;
TVariable_Listz = TObjectList<TVariablex>;
Kod: Tümünü seç
{ TVariable_List }
constructor TVariable.Create;
begin
inherited Create;
FVariable_Attr_List := TVariable_Attr_List.Create;
end;
destructor TVariable.Destroy;
begin
FVariable_Attr_List.Free;
inherited Destroy;
end;
{ TVariablex }
constructor TVariablex.Create;
begin
inherited Create;
FVariable_Attr_List := TVariable_Attrx_List.Create;
end;
destructor TVariablex.Destroy;
begin
FVariable_Attr_List.Free;
inherited Destroy;
end;
{ TVariablez }
constructor TVariablez.Create;
begin
inherited Create;
FVariable_Attr_List := TVariable_Attrz_List.Create;
end;
destructor TVariablez.Destroy;
begin
FVariable_Attr_List.Free;
inherited Destroy;
end;
Kod: Tümünü seç
var
t: TVariable_List;
x: TVariable_Listx;
z: TVariable_Listz;
i: Integer;
j: Integer;
begin
Screen.Cursor := crHourGlass;
try
t := TVariable_List.Create;
for j := 0 to 10000000 do
begin
t.Add(TVariable.Create);
{t.last.Data_ID := j;
for i := 0 to 1000 do
begin
t.Last.Variable_Attr_List.Add(TVariable_Attr.Create);
t.Last.Variable_Attr_List.Last.Name := IntToStr(i);
t.Last.Variable_Attr_List.Last.Value := IntToStr(i);
end;}
end;
t.Free;
x := TVariable_Listx.Create;
for j := 0 to 10000000 do
begin
x.Add(TVariablex.Create);
end;
x.Free;
z := TVariable_Listx.Create;
for j := 0 to 10000000 do
begin
z.Add(TVariablex.Create);
end;
z.Free;
finally
Screen.Cursor := crDefault;
end;
end;
Kullandığım ortam: Delphi XE2 (Update 1), Windows 10