[fpc-pascal] How to find the return type of a for..in ?

Michael Van Canneyt michael at freepascal.org
Thu Jun 16 18:10:40 CEST 2016



On Thu, 16 Jun 2016, Graeme Geldenhuys wrote:

> On 2016-06-16 16:49, Michael Van Canneyt wrote:
>> The return type of the GetEnumerator function tells you what the class is.
>
> Actually, not quite. In the case of TJSONObject, it returns a base type
> enumerator:  TBaseJSONEnumerator
>
> But if you look at the actual code of TJSONObject.GetEnumerator(), then
> you will notice that the actual type returned is TJSONObjectEnumerator.
>
> So by simply looking at the TJSONObject class interface you don't know
> the real type. Yes you could of course query it, but the return type is
> not obvious until you look at the actual implementation.
>
>
>> It is a good idea for a Lazarus IDE extension.
>
> Yes, I would imagine some IDE magic to code complete a for..in statement
> would be quite useful. But then is also shows how badly designed (again
> thanks to Delphi) the for..in statement is. It's not very friendly
> without "IDE magic".

Since the enumerator is an interface/class: you will never know what is
instantiated. You will only know the top-level 'declared' class.

Michael.



More information about the fpc-pascal mailing list