小编Del*_*der的帖子

如何在Delphi中调用TObjectDictionary的继承构造函数

在阅读了 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;
Run Code Online (Sandbox Code Playgroud)

我这样编写构造函数:

  { TAnsiStringList }

    constructor TAnsiStringList.Create(const OwnsObjects: Boolean = True);
    begin
      if OwnsObjects then
        inherited Create([doOwnsKeys,doOwnsValues])
      else
        inherited Create;
    end;
Run Code Online (Sandbox Code Playgroud)

...期望将调用此 TObjectDictionary 构造函数:

    constructor Create(Ownerships: TDictionaryOwnerships; ACapacity: Integer = 0); overload;
Run Code Online (Sandbox Code Playgroud)

...如果指定了 Ownerships 参数。如果未指定 Ownerships 参数,我预计将调用以下继承的 TDictionary 构造函数:

    constructor Create(ACapacity: Integer = 0); overload;
Run Code Online (Sandbox Code Playgroud)

代码编译并运行,但是当我调用时

    inherited Create([doOwnsKeys,doOwnsValues]) I get the …
Run Code Online (Sandbox Code Playgroud)

delphi generics constructor inherited

1
推荐指数
1
解决办法
1605
查看次数

标签 统计

constructor ×1

delphi ×1

generics ×1

inherited ×1