> What works is:
> 
> for each($atItems;$tItem;$i)
>     $myCollection{$tItem} :=  Num($myCollection{$tItem}) +
> $alBackorders{$i})
> end for each

Sorry, I didn't read the original problem carefully enough. This is the best 
way to do it:

// Set each item to 0 to start
for each ($items; $item)
    $myCollection{$item} := 0
end for each

// Now accumulate
for each ($items; $item; $i)
   $myCollection{$item} += $backorders{$i}
end for each


> It seems, that by default (aka. prior to set it explicitly to a numeric
> value), the collection value is created as a string.

What's happening is that in your version, the first time you access 
$myCollection{$tItem}, it doesn't exist, which returns an empty string. This is 
the documented behavior. That's why num() was necessary, but it is actually 
only necessary the first time. That's why I recommend my code, it is much 
clearer what is going on.


> I'm still wondering, how to declare a collection item with a compiler
> declaration.

There is no point in this case, but it would be:

c_longint($myCollection{$tItem})

But $myCollection{$tItem} := 0 is equivalent and clearer, since you are 
accumulating values.


> Furthermore I found, that by storing the collection handle in a session and
> then populating the collection, a4d.debug.dump session tells me, that the
> whole collection is stored within the session. I would have expected, that
> only the collection handle is stored in the session.

Only the handle is stored in the session. If you look at the docs for 
a4d.debug.dump session, it says that it is calling 'dump collection', and the 
docs for that method say at the end:

"If an item of a collection is itself a collection reference, this method is 
called recursively to display its contents."


> And I can only access an item later on through
> 
> session{"myCollection"}{$tItem}
> 
> but not directly through
> 
> $myCollection{$tItem}
> 
> although I've created a global collection.
> 
> Maybe I'm missing something?

$myCollection is a local variable that only survives the current execution 
scope within the current request. That's why there are sessions, so you can 
access values across requests.

Regards,

   Aparajita
   www.aparajitaworld.com

   "If you dare to fail, you are bound to succeed."
   - Sri Chinmoy   |   www.srichinmoy.org

_______________________________________________
Active4D-dev mailing list
[email protected]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://vasudev.aparajitaworld.com/archive/active4d-dev/

Reply via email to