On 23.12.2022 15:50, Andrew Haines via fpc-pascal wrote:
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'])]
Indeed. I would say that is a bug and therefore I reported it:
https://gitlab.com/freepascal.org/fpc/source/-/issues/40058
I usually use the scoped enums but in case the enum values are not valid
identifiers this is the perfect way to handle them. Therefore thanks for
the idea :) I use attributes for various things but didn't realize this
possibility.
Ondrej
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal