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

Sven Barth pascaldragon at googlemail.com
Fri Dec 23 14:40:43 CET 2022


Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org>
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 <fpc-pascal at lists.freepascal.org>
> > 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/
> >>>
> >>> 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
> >>> values. I am recieving them as json that I dont have control over. I am
> >> using
> >>> typeinfo to fill in all the properties but I would like to convert the
> >>> strings I am receiving to the enum values semi-automatically.
> >>>
> >>> LString := 'STATUS';
> >>>
> >>> LHelper := GetHelper(LPropInfo^.PropType); // enum proptype
> >>
> >> Since there can be multiple type helpers for a type, this will never be
> >> possible. At best you would get a list.
> >>
> >> But I don't think there is even a list of type helpers per type.
> >> Sven will need to confirm.
> >>
> >
> > As the active helper(s) for a type change(s) depending on the current
> scope
> > (e.g. in unit A it might be a different helper than in unit B) this is
> not
> > possible. Also helpers are not in any way usable on their own except to
> > retrieve their RTTI information.
>
> But theoretically it should be possible to generate and get a list of all
> defined type helpers, whether they are in scope or not ?
>

No, because the compiler doesn't keep track of that. It's only interested
in what is in scope *right now*.


> If their RTTI could include a function that returns an interface, you could
> retrieve that and do as the OP suggests..
>

Don't make helpers to something that they're simply not there for.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20221223/2c87c526/attachment.htm>


More information about the fpc-pascal mailing list