Re: Referencing values in an array



Daniel,

Using the following structure instead leads to the wanted results:

   MyShape shape$i $i;
   set shapes($i) shape$i;

Just some remarks from my side ...

1. In the original line ...

MyShape shape $i;

... you stumbled over the explicit naming of the MyShape instance.
"shape",
as created above, will be re-created (in XOTcl terminology) in each
iteration
of the loop. By setting implicitly naming the objects ("shape$i") you
definitely solve the issue,
but XOTcl offers you alternatives. I personally find that encoding the
value $i three times
(object name, attribute id, key of shapes array) is a litte
superfluous for my taste.

2. You seem to devise the shapes array as devise to store MyShape
instances in
an addressable "store". Well, you double your efforts here, that's
what an object system
should do for you. XOTcl does (in many flavours).

Consider the following:

package req XOTcl
namespace import ::xotcl::*

Class MyShape -slots {
Attribute id
}
#
# In XOTcl, class are class-objects, that is
# they may be declared per-object behaviour
# (think of 'static' in class-centric languages
# such as Java, C#, ...)
#
MyShape proc getShapes {} {
for {set i 0} {$i < 5} {incr i} {
#
# 1. [self] unfolds to ::MyShape,
# i.e. is the self-reference
# to the current object ...
#
# 2. "new" assigns an auto-generated
# identifier to the created object.
set shape [[self] new -id $i]
puts "Orig: [$shape id]";
}
#
# Well, the class object can inform
# you about existing offsprings ...
# You may access this information
# by means of XOTcl's introspection:
# ::xotcl::Object->info() or
# ::xotcl::Class->info()
foreach s [::MyShape info instances] {
puts "After: [$s id]";
}

}

MyShape getShapes
.



Relevant Pages

  • Re: Detecting the deletion or grouping of a shape
    ... || need to change the forecolor of all shapes held in AShapesSubset ... Dim MyShape As Shape ... Set MyShape = ActiveDocument.Shapes _ ...
    (microsoft.public.word.vba.general)
  • Re: Please help with my code
    ... In addition to removing the shapes, I also like to include the code to ... Dim myshape As Shape ... Dim rng As Range ... For Each myshape In ActiveSheet.Shapes ...
    (microsoft.public.excel.programming)
  • Re: Deletion problem
    ... for each myshape in .shapes ... There are lots of things that qualify for shapes that you ... Is there a way of selecting ANY objects within an range of cells ... Dave Peterson ...
    (microsoft.public.excel.programming)
  • Re: Deletion problem
    ... Dim myRng as range ... for each myshape in .shapes ... There are lots of things that qualify for shapes that you may ... Is there a way of selecting ANY objects within an range of cells ...
    (microsoft.public.excel.programming)
  • Re: VBA ActiveSheet.Shapes. ...
    ... Eigentlich sollte je Zelle nur ein Shapes eingefügt worden sein. ... dass die übernommene Tabelle teilweise mehrere Shapes je Zelle hat. ... Wie kann ich per VBA mir z.B. in einer extra eingefügten Spalte die entsprechende Anzahl eintragen lassen. ... For Each myShape In ActiveSheet.Shapes ...
    (microsoft.public.de.excel)