[WayBack] I want to annotate some of my enumerated types with human facing names. So I want to write: type[Names(‘Explicit time domain’, ‘Implicit time domain’,… – David Heffernan – Google+
This does not work:
constructor Create(const Values: array of string);
It seems to be in QC.
The reason is not obvious until you realise (thanks Stefan for wording that) that attribute constructor arguments are limited to anything that can be const. Open arrays nor dynamic arrays can be const (yes, nowadays you can have “consts” that are dynamic arrays but in fact they are compiler protected variables).
An alternative you might think works, but fails us using one attribute per enumeration element. But that’s where Delphi RTTI leaves you in the dark: it does not expose the RTTI for enumeration elements (likely doesn’t even generate it), only the the enumeration type itself.
So this fails:
type NameAttribute = class( TCustomAttribute ) private FName: String; public constructor Create( AName : String ); property Name: String read FName; end; TMyEnumeration = ( [Name('One')] meOne, [Name('Two')] meTwo );
–jeroen