Delphi 2010 和泛型

Delphi 2010 and Generics

我正在尝试执行以下操作:

type
  IExemplo<Generic> = interface
    function GetGenerico: Generic;    
  end;

  TClassA<Generic> = class(TComponent, IExemplo<Generic>)
    function GetGenerico: Generic; virtual;
    function GetInterface: IExemplo<Generic>; virtual;
  end;

  TClassB = class(TClassA<string>)
    function GetGenerico: string; override;
    function GetInterface: IExemplo<string>; override;
  end;

换句话说,我创建了一个接口,它有一些泛型,一个实现接口的基础 class,最后是一个派生的 class 来实现基础 class。

但是,在行

function GetInterface: IExemplo<string>; override;

我收到语法错误。

我的目标是 TClassB 不再具有 Generic 属性,此时它的类型已经正确设置。

此代码有效,可在更高版本的 Delphi 中编译。事实上,它为我编译了 Delphi 2010,所以我想知道你是否没有安装 all the updates that are available for Delphi 2010.

Delphi 泛型在早期版本中充满了缺陷。在一定程度上,最实用的方法是升级到 Delphi 的现代版本,以摆脱这些缺陷的困扰。是的,您可以通过安装更新​​到 Delphi 2010 来解决这个问题,但我相信您很快就会遇到泛型的其他问题。