Scoped Enums (Delphi)
Go Up to Delphi Compiler Directives (List) Index
|
Type |
Switch |
|
Syntax |
{$SCOPEDENUMS ON}, or {$SCOPEDENUMS OFF} |
|
Default |
{$SCOPEDENUMS OFF} |
|
Scope |
Local |
Remarks
The $SCOPEDENUMS directive enables or disables the use of scoped enumerations in Delphi code. More specifically, $SCOPEDENUMS affects only definitions of new enumerations, and only controls the addition of the enumeration's value symbols to the global scope.
In the {$SCOPEDENUMS ON} state, enumerations are scoped, and enum values are not added to the global scope. To specify a member of a scoped enum, you must include the type of the enum. For example:
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;
Note that this is also valid:
Writeln(Integer(TFoo.A));
Even though TFoo was not declared with $SCOPEDENUMS ON, the A value can still be explicitly resolved using the enumeration name.