On Mon, 10 Nov 2008, Mindaugas Kavaliauskas wrote:

Hi Mindaugas,

> PROC main()
> LOCAL aCountry, aI
>    aCountry := {"LTU"=>"Lithuania", "ZWE"=>"Zimbabwe"}
>    FOR EACH aI in aCountry
>      QOUT(aI:__enumKey)              // OK
>      EVAL({|| QOUT(aI:__enumKey)})   // RTE
>    NEXT
> RETURN

It's expected and correct behavior. Variables stored in codeblocks
are detached. During detaching enumerators becomes simple references
to iterated items which is not later changed.
It allows to create code like:

   proc main()
      local aCountry, aBlocks, aI, aB
      aCountry := {"LTU"=>"Lithuania", "ZWE"=>"Zimbabwe"}
      aBlocks := array( len( aCountry ) )
      FOR EACH aI, aB in aCountry, aBlocks
         aB := {|x| iif( pcount()==0, aI, aI := x ) }
      NEXT
      ? eval( aBlocks[ 1 ] )
      ? eval( aBlocks[ 1 ], "XXXXX" )
      ? eval( aBlocks[ 1 ] )
      ? eval( aBlocks[ 2 ] )
      ? eval( aBlocks[ 2 ], "YYYYY" )
      ? eval( aBlocks[ 2 ] )
   return

As you can see this code does not fail when codeblocks are
evaluated autside FOR EACH loop and in each codeblocks aI
referes to separated aCountry item which were valid when
codeblock was created.

best regards,
Przemek
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to