Re: [fpc-pascal] How to find the return type of a for..in ?
On Thu, 16 Jun 2016 17:49:53 +0200 (CEST) Michael Van Canneyt wrote: >[...] > The return type of the GetEnumerator function tells you what the class is. > > It is a good idea for a Lazarus IDE extension. Lazarus' code completion supports for-in loop since a long time. Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to find the return type of a for..in ?
El 16/06/16 a les 17:49, Michael Van Canneyt ha escrit: It is a good idea for a Lazarus IDE extension. Lazarus 1.4.4 with fpc 2.6.4 can already auto-declare an iterator variable, e.g. var a:TJSONObject; begin for i in a do end; ctrl+shift+c on the i inserts a i: TJSONEnum declaration. Bye -- Luca ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to find the return type of a for..in ?
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. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to find the return type of a for..in ?
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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to find the return type of a for..in ?
On Thu, 16 Jun 2016, Graeme Geldenhuys wrote: On 2016-06-16 15:29, Mattias Gaertner wrote: Have you seen this page: Yes, that's what I looked at to see how to use for..in but nowhere does it mention or give a JSON example. Granted, I haven't read every single word on that page, but a lot seem to cover how to implement an iterator for your own containers so for..in loops can work with it. This was not what I was looking for. The fpjson unit already supports the for..in loop, I just didn't know [immediately obvious] what data type the loop variable must be - hence my question. So it seems the only way to use for..in on moderate to complex objects [that you haven't looped before], is to delve into the source code and see how the enumerator class was implemented, and there you will find the loop variable type to use. The return type of the GetEnumerator function tells you what the class is. It is a good idea for a Lazarus IDE extension. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to find the return type of a for..in ?
On 2016-06-16 15:29, Mattias Gaertner wrote: > Have you seen this page: Yes, that's what I looked at to see how to use for..in but nowhere does it mention or give a JSON example. Granted, I haven't read every single word on that page, but a lot seem to cover how to implement an iterator for your own containers so for..in loops can work with it. This was not what I was looking for. The fpjson unit already supports the for..in loop, I just didn't know [immediately obvious] what data type the loop variable must be - hence my question. So it seems the only way to use for..in on moderate to complex objects [that you haven't looped before], is to delve into the source code and see how the enumerator class was implemented, and there you will find the loop variable type to use. Regards, Graeme ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to find the return type of a for..in ?
On Thu, 16 Jun 2016 14:59:47 +0100 Graeme Geldenhuys wrote: >[...] > 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? Have you seen this page: http://wiki.freepascal.org/for-in_loop Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal