Native namespace for nested enums in Delphi

Is there a way to nest delphi nested enumerations in my own namespace?

This code creates E2004: The identifier is updated since both enumerations contain "unknown".

TMyType1 = class public type TMyType1Enum = (unknown, val1, val2); public constructor Create(); ... end; TMyType2 = class public type TMyType2Enum = (unknown, other1, other2, other3); // causes E2004 public constructor Create(); ... end; 

In C ++, enumeration element identifiers were in different areas (TMyType1 :: unknown and TMyType2 :: unknown).

Is it possible to achieve something similar in Delphi, except for pre- or suffixation of identifiers (MyType1EnumUnknown, MyType1EnumVal1, ..., MyType2Enumunknown, ...)?

+8
enums delphi delphi-xe2
source share
1 answer

Try $SCOPEDENUMS . From http://docwiki.embarcadero.com/RADStudio/en/Scoped_Enums_(Delphi) :

 type TFoo = (A, B, Foo); {$SCOPEDENUMS ON} TBar = (A, B, Bar); {$SCOPEDENUMS OFF} begin WriteLn(Integer(Foo)); WriteLn(Integer(A)); // TFoo.A WriteLn(Integer(TBar.B)); WriteLn(Integer(TBar.Bar)); WriteLn(Integer(Bar)); // Error end; 
+10
source share

All Articles