如何在泛型类中声明枚举类型的集合类型

Ren*_*ann 5 delphi generics delphi-xe4

我在Delphi XE4中遇到了一些奇怪的行为.

我不能set在泛型类中声明一个类型,其中序数类型在同一个类中声明.

例如:

TTest<T> = class(TObject)
type
  TEnumType  = (eOne, eTwo, eThree);
  TEnumTypes = set of TEnumType;
end;
Run Code Online (Sandbox Code Playgroud)

以上不编译.编译器发出错误" E2001:Ordinal type required ".

一个非泛型的类

TTest = class(TObject)
type
  TEnumType  = (eOne, eTwo, eThree);
  TEnumTypes = set of TEnumType;
end;
Run Code Online (Sandbox Code Playgroud)

编译.

要使泛型类成功编译,必须在类外声明序数类型:

TEnumType  = (eOne, eTwo, eThree);
TTest<T> = class(TObject)
type
  TEnumTypes = set of TEnumType;
end;
Run Code Online (Sandbox Code Playgroud)
  1. 这种行为是否被视为错误?如果是,是否已在更高版本中修复?
  2. 有没有人有另一种解决方法?我想在类中声明类型,因为它们仅在此类的私有部分中使用.

Dav*_*nan 5

这确实是一个在以后的版本中修复的错误.例如,您的代码在XE7中编译.很可能它会在XE5或XE6中编译,但我没有立即交给他们检查.