Bug in tCollection.ForEach?

In article <0d0_9506260...@dosgg.dosgg.nl> Teunis.Rossi...@p6583.f109.n500.z1.fidonet.org (Teunis Rossingh) writes:

Quote
>In one of my programs I use a collection of collections.
>When I wrote a routine to do some calculations on all items in
>this construction using the standard method FOREACH, my program
>didn't respond as I expected.

This isn't a bug, just a misuse of them.  The documentation isn't clear that
what you're doing is wrong, but it is:

Quote
>FUNCTION tSecondColl.calcTotal : integer;
>VAR subTotal : integer;
>  PROCEDURE addObject(obj : pMyObject); FAR;
>  BEGIN subTotal := subTotal + obj^.value END;
>  PROCEDURE addFirstColl(coll : pFirstColl); FAR;
>  VAR i : integer;
>  BEGIN coll^.forEach(@addObject) END;

Here's the problem.  Your addObject procedure is a local procedure, but that's
not enough:  it has to be local to the routine that calls ForEach.  Change
this part of your code as shown and things should be fine:

FUNCTION tSecondColl.calcTotal : integer;
VAR subTotal : integer;

  PROCEDURE addFirstColl(coll : pFirstColl); FAR;
    PROCEDURE addObject(obj : pMyObject); FAR;
    BEGIN subTotal := subTotal + obj^.value END;

  BEGIN coll^.forEach(@addObject) END;

(I deleted the declaration of i here because you weren't using it; this really
has nothing to do with the problem.)

Duncan Murdoch