Re: [fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-25 Thread Ondrej Pokorny via fpc-pascal
Am 23.12.2022 um 15:50 schrieb Andrew Haines via fpc-pascal: Error: Ordinal expression expected [TEnumAttr(['YES', 'NO', 'COULD_BE'])] There is another (and cleaner) approach that uses an abstract attribute class. See attachment. The advantage is that the compiler warns you with an error

Re: [fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-23 Thread Ondrej Pokorny via fpc-pascal
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;    

Re: [fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-23 Thread Michael Van Canneyt via fpc-pascal
On Fri, 23 Dec 2022, Sven Barth wrote: Michael Van Canneyt via fpc-pascal schrieb am Fr., 23. Dez. 2022, 10:48: On Fri, 23 Dec 2022, Sven Barth via fpc-pascal wrote: Michael Van Canneyt via fpc-pascal schrieb am Fr., 23. Dez. 2022, 08:18: On Thu, 22 Dec 2022, Andrew Haines via

Re: [fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-23 Thread Andrew Haines via fpc-pascal
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

Re: [fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-23 Thread Sven Barth via fpc-pascal
Michael Van Canneyt via fpc-pascal schrieb am Fr., 23. Dez. 2022, 10:48: > > > On Fri, 23 Dec 2022, Sven Barth via fpc-pascal wrote: > > > Michael Van Canneyt via fpc-pascal > > schrieb am Fr., 23. Dez. 2022, 08:18: > > > >> > >> > >> On Thu, 22 Dec 2022, Andrew Haines via fpc-pascal wrote: >

Re: [fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-23 Thread Ondrej Pokorny via fpc-pascal
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

Re: [fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-23 Thread Michael Van Canneyt via fpc-pascal
On Fri, 23 Dec 2022, Sven Barth via fpc-pascal wrote: Michael Van Canneyt via fpc-pascal schrieb am Fr., 23. Dez. 2022, 08:18: On Thu, 22 Dec 2022, Andrew Haines via fpc-pascal wrote: Hi what I want to do is similar to this question here:

Re: [fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-23 Thread Sven Barth via fpc-pascal
Michael Van Canneyt via fpc-pascal schrieb am Fr., 23. Dez. 2022, 08:18: > > > On Thu, 22 Dec 2022, Andrew Haines via fpc-pascal wrote: > > > Hi what I want to do is similar to this question here: > > > https://en.delphipraxis.net/topic/423-rtti-determine-record-helper-type-for-a-base-type/ > >

Re: [fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-22 Thread Michael Van Canneyt via fpc-pascal
On Thu, 22 Dec 2022, Andrew Haines via fpc-pascal wrote: Hi what I want to do is similar to this question here: https://en.delphipraxis.net/topic/423-rtti-determine-record-helper-type-for-a-base-type/ I am going to create multiple type helpers for enums and I would like to look up the

Re: [fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-22 Thread Andrew Haines via fpc-pascal
So, I came up with a solution using Custom Attributes. I can declare this: [TEnumAttr('YES', 'NO', 'COULD_BE')]   TMyEnum = (meYes, meNo, meCouldBe); and at runtime look for the TEnumAttr attribute and use that. TEnumAttr = class(TCustomAttribute)   protected     FValues: TStringArray;    

[fpc-pascal] Unrelated type helpers with the same members? Implement an interface with a type helper?

2022-12-22 Thread Andrew Haines via fpc-pascal
Hi what I want to do is similar to this question here: https://en.delphipraxis.net/topic/423-rtti-determine-record-helper-type-for-a-base-type/ I am going to create multiple type helpers for enums and I would like to look up the helper and use common methods AsString AsOrdinal to get/set the