[fpc-pascal] How to find the return type of a for..in ?
Graeme Geldenhuys
mailinglists at geldenhuys.co.uk
Thu Jun 16 15:59:47 CEST 2016
Hi,
I've never really used the for..in in real code, because I think the
iterator is very limited. I've implemented much more flexible iterators
for most container types.
Here is another stumbling block of for.in usage. The statement itself
doesn't give you any hint as to what the return type is. What is the
correct way of finding the return type of a for..in statement? I need to
define a variable of some or other type. The container's Iterate()
method doesn't give any hints. Neither does the container's
GetEnumerator() method. I then had to dig into the source code of the
return type of GetEnumerator() to finally find the Current property and
it's return type.
And before you say it, the for..in return type is not always very
obvious. eg: if you use for..in over a TJSONObject the return type is
not TJSONData, but rather TJSONEnum. And as that name [badly] suggests,
it isn't actually an enum (as per the Object Pascal language
definition). It is in fact a Record structure.
Regards,
Graeme
More information about the fpc-pascal
mailing list