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

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Thu Jun 16 17:57:55 CEST 2016


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".

Regards,
  Graeme



More information about the fpc-pascal mailing list