是否可以在Delphi中为通用记录创建类型别名

时间:2013-04-22 14:56:00

标签: delphi generics

我想为通用记录定义记录类型(类型别名)。我想这样做,因此单元b的用户可以在不使用单元a的情况下访问TMyGenericRecord。我有这样的单位:

unit a;
interface
type
  TMyNormalRecord = record
    Item: Integer;
  end;
  TMyGenericRecord<T> = record
    Item: T;
  end;
implementation
end.

unit b;
interface
type
  TMyNormalRecord = a.TMyNormalRecord;  // works
  TMyGenericRecord<T> = a.TMyGenericRecord<T>; // E2508 type parameters not allowed on this type
implementation
end.

1 个答案:

答案 0 :(得分:4)

该问题的简单答案是该语言不支持泛型类型别名。

only places where you can use generic parameters是:

  1. 通用class, interface, record and array types
  2. 通用procedural types
  3. 通用methods
相关问题