2

How to access associative array member of a class inside the class itself? Itcl is modeled after C++, and in C++ we would write:

SomeObject.SomePublicMember = ...

How to do the same in Itcl? Without providing accessor procedure for such an array. I've seen that for usual plain variables this can be obtained by using cget:

$this cget -PublicMemberVariableName

However the following construct doesn't work:

$this cget -AssociativeArrayName(NamedIndex)

Is this possible at all?

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Aryaps
  • 21
  • 1

1 Answers1

2

Alas, cget won't get what you want. The array element isn't passed all the way down to ItclGetInstanceVar (I'm not sure why).

You can use get/set and the like:

class myObject {
   public variable AssArray
   constructor {} {
      array set AssArray ""
   }
   method setArr { elem val } {
      set AssArray($elem) $val
   }
   method getArr { elem } {
      return $AssArray($elem)
   }
   method getFullArr {} {
      return [array names AssArray]
}
ctd
  • 1,693
  • 12
  • 27