properties as objects, reference life?

It seems like properties of objects which themselves are other objects should behave the same as the parent object in terms of referencing. What I mean is …

Say an ObjectA has several properties, one of which is another ObjectB, which itself has properties, among them: i as an integer. So we can get i by:


Now say I have an array of these ObjectsA()

And say I want to change the values of i for certain members of this array according to certain conditions met by other properties of members of ObjectsA(), the new values requiring array-oriented sorting and calculation.

I can create an array of ObjectsB() by something like the following:

[code]// make an array of ObjectsB from ObjectsA according to someparam
dim ObjectsB() as ClassOfObjectB
for n as integer = 0 to ObjectsA.Ubound
if ObjectsA( n ).someparam > -1 then ObjectB.append ObjectsA( n ).ObjectB
next n

// change the values of i for these ObjectsB() according to some external logic
for n as integer = 0 to ObjectsB.Ubound
if SatisfysConditions( ObjectsB( n ) ) then ObjectsB( n ).i = SomeExternalLogic( ObjectsB( n ) )
next n

After I’ve done this, I should be able to go back to the ObjectsA() array, and see that I’ve successfully changed the values of those ObjectB.i properties that were referenced in my ObjectsB() array.

My problem is, I am doing this, yet the values of ObjectsA( n ).ObjectB.i aren’t changing.

The paths the objects take in my actual code are much more convoluted than what I show here, but I’ve looked very carefully at my code to make sure that I never destroy or recreate a reference during the process of assigning a new value. The reference should be maintained throughout, but somehow after setting the value, the object from the original array of ObjectsA hasn’t been changed. Is there something different about the reference life of an object that exists as a property of another object?

No, your pseudo-code is right and will do what you want. Look again at your actual code. Trace as needed.

A neat trick is to convert i to a Computed Property so you can put a breakpoint into its Set method. That way you can see exactly when it’s changed.

Thanks, Kem; I’m glad to know it’s just my mistake somewhere and not impossible by design. I’ll keep looking!

… and thanks for the tip about the computed property.

Thank @Norman Palardy. I picked it up from him at XDC. :slight_smile: