How to declare an enumeration type set type in a common class

I came across some weird behavior in Delphi XE4.

I cannot declare a set type in a generic class where the ordinal type is declared inside the same class.

For instance:

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

The above does not compile. The compiler emits the error "E2001: requires an ordinary type."

Not a common class e.g.

 TTest = class(TObject) type TEnumType = (eOne, eTwo, eThree); TEnumTypes = set of TEnumType; end; 

compiles.

To successfully compile a general class, the ordinal type must be declared outside the class:

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

  • Is this behavior a mistake? If so, is it fixed in a later version?
  • Does anyone have another workaround? I wanted to declare types inside a class because they are used exclusively in private parts of this class.
+5
source share
2 answers

From a glance at the tracker, the problems seem to be regression around XE3 / XE4, which is fixed in later versions:

+4
source

This is really a bug that has been fixed in later versions. For example, your code compiles in XE7. It is possible that it will compile in XE5 or XE6, but I cannot check them right away.

+5
source

Source: https://habr.com/ru/post/1258804/


All Articles