我定义了一个 Objectlist 来存储几个 Polygons 作为 TFPolygon = array of TPoint inside this TObjectList; 但是使用我的 objectlist 的 add 函数,我得到一个访问冲突错误:
type
TFPolygon = array of TPoint;
TFPolygonList = class(TObjectList)
private
procedure SetPolygon(Index: Integer; Value: TFPolygon);
function GetPolygon(Index: Integer): TFPolygon;
public
procedure Add(p: TFPolygon);
property Items[index: Integer]: TFPolygon read GetPolygon write SetPolygon; default;
end;
implementation
procedure TFPolygonList.SetPolygon(Index: Integer; Value: TFPolygon);
begin
inherited Items[Index] := Pointer(Value);
end;
function TFPolygonList.GetPolygon(Index: Integer): TFPolygon;
begin
Result := TFPolygon(inherited Items[Index]);
end;
procedure TFPolygonList.Add(p: TFPolygon);
begin
inherited Add(Pointer(p));
end;
我无法理解此代码示例中的错误?我可以只将类存储在 TObjectList 中,还是我存储 TPoints 数组的方法也有效?