<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Michael Van Canneyt via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Fr., 23. Dez. 2022, 10:48:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On Fri, 23 Dec 2022, Sven Barth via fpc-pascal wrote:<br>
<br>
> Michael Van Canneyt via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a>><br>
> schrieb am Fr., 23. Dez. 2022, 08:18:<br>
><br>
>><br>
>><br>
>> On Thu, 22 Dec 2022, Andrew Haines via fpc-pascal wrote:<br>
>><br>
>>> Hi what I want to do is similar to this question here:<br>
>>><br>
>> <a href="https://en.delphipraxis.net/topic/423-rtti-determine-record-helper-type-for-a-base-type/" rel="noreferrer noreferrer" target="_blank">https://en.delphipraxis.net/topic/423-rtti-determine-record-helper-type-for-a-base-type/</a><br>
>>><br>
>>> I am going to create multiple type helpers for enums and I would like to<br>
>> look<br>
>>> up the helper and use common methods AsString AsOrdinal to get/set the<br>
>>> values. I am recieving them as json that I dont have control over. I am<br>
>> using<br>
>>> typeinfo to fill in all the properties but I would like to convert the<br>
>>> strings I am receiving to the enum values semi-automatically.<br>
>>><br>
>>> LString := 'STATUS';<br>
>>><br>
>>> LHelper := GetHelper(LPropInfo^.PropType); // enum proptype<br>
>><br>
>> Since there can be multiple type helpers for a type, this will never be<br>
>> possible. At best you would get a list.<br>
>><br>
>> But I don't think there is even a list of type helpers per type.<br>
>> Sven will need to confirm.<br>
>><br>
><br>
> As the active helper(s) for a type change(s) depending on the current scope<br>
> (e.g. in unit A it might be a different helper than in unit B) this is not<br>
> possible. Also helpers are not in any way usable on their own except to<br>
> retrieve their RTTI information.<br>
<br>
But theoretically it should be possible to generate and get a list of all <br>
defined type helpers, whether they are in scope or not ?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">No, because the compiler doesn't keep track of that. It's only interested in what is in scope *right now*. <br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
If their RTTI could include a function that returns an interface, you could<br>
retrieve that and do as the OP suggests..<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Don't make helpers to something that they're simply not there for. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div></div>