给你一个类似的代码吧,我自己做的。你拿去改一改吧。
TFeatures = class //符号属性集类
private
FCount :SmallInt;
FFeatures :array of TFeature;
function GetCount :SmallInt;
function GetFeature(Index: Integer) :TFeature;
public
procedure Add(Feature: TFeature);
procedure Remove(Index: Integer);
procedure RemoveAll;
constructor Create; overload;
destructor Destroy; override;
property Items[Index: Integer] :TFeature read GetFeature;
published
property Count :SmallInt read GetCount;
end;
constructor TFeatures.Create;
begin
FCount:=0;
SetLength(FFeatures, FCount);
end;
destructor TFeatures.Destroy;
var
i:integer;
begin
for i:=0 to Length(FFeatures)-1 do FFeatures.Free;
inherited;
end;
procedure TFeatures.Add(Feature: TFeature);
begin
FCount:=Length(FFeatures);
SetLength(FFeatures, FCount+1);
FFeatures[FCount]:=Feature;
FCount:=FCount+1;
end;
procedure TFeatures.Remove(Index: Integer);
var
i : integer;
begin
if Index>FCount-1 then Application.MessageBox('此索引大于最大值!', '提示', 0)
else begin
for i:=Index to FCount-2 do FFeatures:=FFeatures[i+1];
FFeatures[FCount-1].Free;
FCount:=FCount-1;
SetLength(FFeatures, FCount);
end;
end;
procedure TFeatures.RemoveAll;
var
i:integer;
begin
for i:=0 to Length(FFeatures)-1 do FFeatures.Free;
FCount:=0;
SetLength(FFeatures, FCount);
end;
function TFeatures.GetFeature(Index: Integer): TFeature;
begin
Result:=nil;
if Index>FCount-1 then Application.MessageBox('此索引大于最大值!', '提示', 0)
else begin
Result:=FFeatures[Index];
end;
end;
function TFeatures.GetCount :SmallInt;
begin
FCount:=Length(FFeatures);
Result:=FCount;
end;