On 12/23/22 5:24 AM, Ondrej Pokorny via fpc-pascal wrote:
This may be simpler:

[TEnumAttr(['YES', 'NO', 'COULD_BE'])]
  TMyEnum = (meYes, meNo, meCouldBe);

TEnumAttr = class(TCustomAttribute)
  protected
    FValues: TStringArray;
    FTypeName: String;
  public
    class function FromType(ATypeInfo: PTypeInfo): TEnumAttr;
    constructor Create(Values: array of string);

---


I tried that first but the compiler gave an error on the "["

Error: Ordinal expression expected

[TEnumAttr(['YES', 'NO', 'COULD_BE'])]


Or, if the enum values are valid identifiers, you can simple use scoped enums:

{$SCOPEDENUMS ON}
  TMyEnum = (YES, NO, COULD_BE);

and the usual TypeInfo methods.

Ondrej


I didn't know about those, that could also be a good solution, thanks!

Andrew

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to