- DelphiTools - https://www.delphitools.info -

Explicitly scoped enums

Oxygene syntax [1] (aka Delphi Prism) for enumerations was recently added to DWScript [2], with both enum and flags contextual keywords.

Enumerations scoping was already in, but optional, using these keywords make scoping explicitly required.

type
   TMyEnum = enum (Alpha, Beta, Gamma);
...
e := TMyEnum.Alpha; // works
e := Alpha; // syntax error

Since the scoping with this declaration syntax is explicit, you’re encouraged not to use prefixing for the enumeration elements, removal of the leading “T” being optional.

Classic enumerations (without keyword) stay globally scoped and unchanged for now (so this addition is fully backward-compatible).

Besides adding support for one more Oxygene syntax elements (alongside method, implies, contracts, etc.), this also provides a cleaner syntax than the {$SCOPEDENUMS} directive-based  approach introduced with Delphi XE2, with which you end up having to wrap enum declarations between directives (cf. VCL & FMX source).