Just pass a local procedure as a parameter to `ForEach', and call it from there. GPC will ensure that the local procedure can access its parent's local variables.
Won't this cause typing violation?
What to you mean ? Of course types will be checked. Look on attached program. It's CORRECT pascal's (standard pascal, not even "pascal with GPC extensions") program. If you'll change x:integer to x:real in first line it'll be not correct pascal parogram and GPC will complain. In GPC you can use not just declaration in procedure's header but also pointers to procedures/functions and such and will work just fine with embedded functions (just like in GCC).
I mean that changing the TYPE of both methods will cause other procedures to fail, causing an incompability with FV.
Keeping the argument a untyped pointer, and then typecasting to a proctype will probably not work, since the mechanics of passing of the "local" procedure is probably based on the parameter being a procedure type.
---
Remarks: - Only two TGROUP (foreach and firstthat) methods are affected, and both methods aren't listed under their own names in tp help, and only accessable via tgroup, so they could be meant as internals. - For Collection.FirstThat in objects.pas the same problem seems to be solved for GPC while keeping a pointer as parameter. Marco van de Voort (MarcoV@Stack.nl) http://www.stack.nl/~marcov/xtdlib.htm