[英]How to declare a set type of an enum type within a generic class
I came across some strange behaviour in Delphi XE4. 我在Delphi XE4中遇到了一些奇怪的行为。
I can't declare a set
type within a generic class, where the ordinal type is declared within the same class. 我无法在泛型类中声明
set
类型,而在同一类中声明了序数类型。
For example: 例如:
TTest<T> = class(TObject)
type
TEnumType = (eOne, eTwo, eThree);
TEnumTypes = set of TEnumType;
end;
The above does not compile. 上面没有编译。 The compiler emits error " E2001: Ordinal type required ".
编译器发出错误“ E2001:需要序数类型 ”。
A non-generic class like 一个非通用类
TTest = class(TObject)
type
TEnumType = (eOne, eTwo, eThree);
TEnumTypes = set of TEnumType;
end;
does compile. 确实可以编译。
For the generic class to compile successfully, the ordinal type has to be declared outside the class: 为了使泛型类成功编译,必须在类外声明序数类型:
TEnumType = (eOne, eTwo, eThree);
TTest<T> = class(TObject)
type
TEnumTypes = set of TEnumType;
end;
This is indeed a bug that is fixed in later versions. 这确实是一个错误,已在更高版本中修复。 Your code compiles in XE7 for instance.
例如,您的代码在XE7中编译。 Quite possibly it will compile in XE5 or XE6, but I don't have them immediately to hand to check.
它很可能会在XE5或XE6中编译,但是我没有立即检查它们。
From looking at the issue tracker it seems to be a regression around XE3/XE4 which got fixed in later versions: 从问题跟踪器来看,它似乎是围绕XE3 / XE4的回归,该回归在以后的版本中得到了修复:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.