我在 Delphi 4 中有这段代码。我创建了 10 个类型的对象T_Charge
(见下文),我将它们添加到TList
名为myList
. 该T_Charge
类型引用了三个类型的对象T_Platte
(见下文)。
释放所有 10 个对象的所有内存的正确方法是什么?因此,对于每个我想释放P1
、P2
、等的内存的对象P3
,F_Treated
以及其myCharge
自身的内存。我尝试了一切,但不断出错。
procedure Test;
var
myList: TList;
myCharge: T_Charge;
begin
myList := TList.Create;
for i := 0 to 9 do
begin;
myCharge := T_Charge.Create(...);
myList.Add(myCharge);
end;
...
end;
type
T_Platte = class(TObject)
private
F_Nummer : Integer;
F_Los : Integer;
F_Dicke : Real;
F_Lange : Real;
F_Breite : Real;
F_QuenchCode : Integer;
F_Geschwindigkeit : Real;
F_Menge : Integer;
F_MengeInLos : Integer;
F_Treated : Boolean;
public
constructor Create(inNummer, inLos: Integer; inDicke, inLange, inBreite, inGeschwindigkeit : Real; inQuenchCode,inMenge: Integer; inTreated: Boolean); overload;
constructor Create(inPlatte: T_Platte); overload;
destructor Destroy; override;
property Nummer: Integer read F_Nummer write F_Nummer;
property Los: Integer read F_Los write F_Los;
property Dicke: Real read F_Dicke write F_Dicke;
property Lange: Real read F_Lange write F_Lange;
property Breite: Real read F_Breite write F_Breite;
property QuenchCode : Integer read F_QuenchCode write F_QuenchCode;
property Geschwindigkeit: Real read F_Geschwindigkeit write F_Geschwindigkeit;
property Menge: Integer read F_Menge write F_Menge;
property MengeInLos: Integer read F_MengeInLos write F_MengeInLos;
property Treated: Boolean read F_Treated write F_Treated;
function getPlattenRecord: string;
end; // class T_Platte
T_Charge = class(TObject)
private
F_P1 : T_Platte;
F_P2 : T_Platte;
F_P3 : T_Platte;
F_Treated : Boolean;
F_Vmin : Real;
F_Qty : Integer;
F_RelationNext : Boolean;
public
constructor Create(inP1, inP2, inP3 : T_Platte; inTreated: Boolean; inVmin: Real; inQty: Integer; inRelationNext: Boolean); overload;
constructor Create(inCharge : T_Charge); overload;
destructor Destroy; override;
property P1: T_Platte read F_P1 write F_P1;
property P2: T_Platte read F_P2 write F_P2;
property P3: T_Platte read F_P3 write F_P3;
property Treated : Boolean read F_Treated write F_Treated;
property Vmin : Real read F_Vmin write F_Vmin;
property Qty : Integer read F_Qty write F_Qty;
property RelationNext : Boolean read F_RelationNext write F_RelationNext;
function getChargeRecord: string;
end; // class T_Charge
constructor T_Platte.Create(inNummer, inLos: Integer; inDicke, inLange, inBreite, inGeschwindigkeit: Real; inQuenchCode,inMenge: Integer; inTreated: Boolean);
begin
F_Nummer := inNummer;
F_Los := inLos;
F_Dicke := inDicke;
F_Lange := inLange;
F_Breite := inBreite;
F_Geschwindigkeit := inGeschwindigkeit;
F_QuenchCode := inQuenchCode;
F_Menge := inMenge;
F_MengeInLos := 0;
F_Treated := inTreated;
end;
constructor T_Charge.Create(inP1, inP2, inP3 : T_Platte; inTreated: Boolean; inVmin: Real; inQty: Integer; inRelatio nNext: Boolean);
begin
F_P1 := T_Platte.Create(inP1);
F_P2 := T_Platte.Create(inP2);
F_P3 := T_Platte.Create(inP3);
F_Treated := inTreated;
F_Vmin := inVmin;
F_Qty := inQty;
F_RelationNext := inRelationNext;
end;