在阅读了 TDictionary 相对于 TStringList 的显着性能改进后,我创建了以下类:
TAnsiStringList = class(TObjectDictionary<AnsiString,TObject>)
public
constructor Create(const OwnsObjects: Boolean = True); reintroduce;
destructor Destroy; override;
procedure Add(const AString: AnsiString);
procedure AddObject(const AString: AnsiString; AObject: TObject);
end;
我这样编写构造函数:
{ TAnsiStringList }
constructor TAnsiStringList.Create(const OwnsObjects: Boolean = True);
begin
if OwnsObjects then
inherited Create([doOwnsKeys,doOwnsValues])
else
inherited Create;
end;
...期望这个 TObjectDictionary 构造函数将被调用:
constructor Create(Ownerships: TDictionaryOwnerships; ACapacity: Integer = 0); overload;
...如果指定了 Ownerships 参数。如果没有指定 Ownerships 参数,我预计会调用以下继承的 TDictionary 构造函数:
constructor Create(ACapacity: Integer = 0); overload;
代码编译并运行,但是当我调用
inherited Create([doOwnsKeys,doOwnsValues]) I get the following error:
无效的类类型转换
有谁看到我做错了什么,有没有合适的方法来做到这一点?
TIA