In
myClass.Remove(),
this.base.objectName is the same as
myClass.objectName and
&this retrieves the address of the parent object, not the child object identified by
name.
In
mySubClass.__New(),
this.base.objectName is the same as
mySubClass.objectName.
Given that an child object's name is logically a property of the child object, it would be much more sensible to store the name in the child object. Why should it be skipped during enumeration (for-loop)? If your object represents an array of items (either sequential or associative) and you wish the for-loop to include only those items, there are multiple options:
[*:voodfqta]Keep a separate array of items in the child object, such as
child.items. You can make
child[key] refer to
child.items[key] by using meta-functions. To make
for key,value in child enumerate only the items, override the _NewEnum() method and just do
return this.items._NewEnum().
[*:voodfqta]Override the _NewEnum() method to return a custom enumerator object which has the behaviour you want. It only needs to implement one method:
Next().Note that in jethrow's example, the following lines are not necessary:
if Not IsObject(this.base.objectName)
this.base.objectName := []
This is because
this.base.objectName[&this] is evaluated as
(this.base)["objectName", &this], which is treated as a "multi-dimensional array". See
Arrays of Arrays for more detail.
Note also that when you do
ObjRemove(this, name), the return value is
this[name] prior to removal. This will probably do the job:
ObjRemove(myClass.mySubClass.objectName, &ObjRemove(this, name))