How to declare a set type of an enum type within a generic class
delphi, delphi-xe4, generics
Solution
From looking at the issue tracker it seems to be a regression around XE3/XE4 which got fixed in later versions:
- http://qc.embarcadero.com/wc/qcmain.aspx?d=126675
- http://qc.embarcadero.com/wc/qcmain.aspx?d=112682
- http://qc.embarcadero.com/wc/qcmain.aspx?d=117200
Problem
I came across some strange behaviour in Delphi XE4. I can't declare a `set` type within a generic class, where the ordinal type is declared within the same class. 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". 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; ``` - Is this behaviour considered a bug? If yes, has it been fixed in a later version? - Does anyone have another workaround? I wanted to declare the types within the class because they are used exclusively in private parts of this class.