[XOTcl] Referencing values in an array



I want to fill an array in a method. The array will be passed to the method and referenced using upvar. Each element in the array should be an instance of the class MyShape:

package require XOTcl

Class MyShape -slots {
Attribute id;
};

MyShape instproc init {id} {
my id $id;
};


proc getShapes {_shapes} {
upvar 1 $_shapes shapes;
for {set i 0} {$i < 5} {incr i} {
# create a MyShape instance. Save it as "shape"
MyShape shape $i;
set shapes($i) shape;
# check the id of the added element
puts "Orig: [$shapes($i) id]";
}
set count [array size shapes];
for {set x 0} {$x < $count} {incr x} {
puts "After: [$shapes($x) id]";
}
};

#define the array
array set shapes {};
# fill the array
getShapes shapes;

I create 5 separate instances of MyShape and ask for their id during creation and directly after all instances are created. During creation I get the correct id ("0" up to "4"), after creation I only get the last element for each array entries (5 times "4").

Where is my mistake?
Daniel
.



Relevant Pages

  • Re: Create array based on shape name or tag
    ... Thanks again, David... ... Grouping the shapes in Normal view isn't an option ... My big hurdle is adding the shapes to the array programatically, ... Dim myShapes As Shapes ...
    (microsoft.public.powerpoint)
  • Re: Create array based on shape name or tag
    ... I've never used it in PowerPoint, ... I'm not sure if you will have to Dim the array to the right size. ... I have sixteen shapes on a slide named "TestArea." ... Set myShapes = ActivePresentation.Slides.Shapes ...
    (microsoft.public.powerpoint)
  • Re: Optimization problem
    ... public class Point { ... Points are gathered in shapes and these form a stage. ... And somewhere else I have a global array: double, where N is the number of points, known in advance. ... So, a packed representation is ~20% faster than a naive representation, whilst the N x 3 representation is actually slower. ...
    (comp.lang.java.programmer)
  • Re: How to initialize an array in VBA of named shapes on a slide?
    ... MS PowerPoint MVP Team ... PowerPoint Video and PowerPoint Sound Solutions www.pfcmedia.com ... There's no problem with declaring an array of shapes. ...
    (microsoft.public.powerpoint)
  • Re: programmatically selecting multiple shapes
    ... Sub AAA ... Dim j As Long, i As Long ... > I can actually get buy with a hardcoded list of shapes, ... I tried that using an array of strings "Array", ...
    (microsoft.public.excel.programming)