[fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?
Andrew Haines
andrewd207 at aol.com
Fri Dec 23 15:50:13 CET 2022
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
More information about the fpc-pascal
mailing list