Correct Use of an Array Computed Property in a Class? Bug?

I seem to be having trouble accessing a computed array property. I have the private backing property array being returned in the Get method of the property.

When trying to access the property like so

dim count as integer count = MyClass.MyComputedArrayProperty.Ubound//compile error count = MyClass.MyPublicArrayProperty.Ubound//no error //work around dim ar() as string ar = MyClass.MyComputedArrayProperty count = ar.Ubound

I get a compiler error “This item does not exist”

Is this a bug? Or expected behavior?

My work around is to create a method that returns an array.

Xojo2018R1

Computed properties cannot be arrays.

Not according to the documentation:
http://developer.xojo.com/userguide/properties

[quote]Type
The Type can be any valid data type, including classes.[/quote]

Am I missing something?

As Jason said, Computed Properties cannot be arrays. I can add that clarification to the Type section on the doc page, but I’m curious how you defined your computed property because you should get a compilation error if you try to create one as an array.

Anyway, if you need to return an array use a method instead.

[quote=392641:@Paul Lefebvre]As Jason said, Computed Properties cannot be arrays. I can add that clarification to the Type section on the doc page, but I’m curious how you defined your computed property because you should get a compilation error if you try to create one as an array.

Anyway, if you need to return an array use a method instead.[/quote]

Thanks. I only received the compilation error when trying to access the array in another part of my code. I’ve changed my code to use a method the return an array.

So, a computed property could be any other class or object? a Dictionary?

Not sure what you mean by “computed method”. A computed property behaves almost identically to a pair of methods - a getter & setter

Sub propertyName(assigns name as Type)
   // this is the setter
end sub

and

Function propertyName() as Type
    // this is the getter
end function

the rest of your app can’t tell the difference between a method pair, computed property or just an exposed property (which is not true in many other languages). The biggest difference is that a computed property cannot be overridden in subclasses, only shadowed, where a get / set pair of methods can be overridden.

I meant computed property.

So to follow up on this, I’m trying to break on any change to an array. I’ve broken on computed scalars, but now need to detect a change to any element.

How can I do this without creating a slew of computed scalars, each corresponding to a single element of the array?

The other difference with computed properties is that the will show up in the debugger if they have implemented Get.

I’m aware of that and use it for scalar values, but as stated above, they’re not supported for arrays. I suppose some awkward array-to-text and back again could be triggered by a change in a larger text item, but that’s crude.

Was hoping others had imagined more elegant workarounds.

Can you describe in more detail exactly what you are attempting to accomplish?

I’d like to break on change (set) to any element of a computed text array while debugging, or emulate that functionality.
As stated above, computed array properties are not supported.

dim dataStore() as string // place this at the proper scope level

sub myArray(indx as Integer, assigns newValue as String)
if indx<0 or indx>=dataStore.ubound then raise an error
if newValue<>dataStore(indx) then break // you just changed the value
dataStore(indx)=newValue
end sub

function myArray(indx as Intege) as String
if indx<0 or indx>=dataStore.ubound then raise an error
return dataStore(indx)
end function

This uses paired overloads, not “computed property” as a CP cannot have passed parameters (ie. subscript)

MyArray(5)="this is a test"
msgbox MyArray(5)

[quote]
this code is presented for illustration purposes, and is not meant to be a cut/paste solution. It is up to the individual developer to decide is any piece is relavant to their project, and to make the required changes[/quote]

[quote=393127:@Michael Gehl]I’d like to break on change (set) to any element of a computed text array while debugging, or emulate that functionality.
As stated above, computed array properties are not supported.[/quote]

You might look into the use of operator_subscript:

http://developer.xojo.com/operator-overloading$Operator_Subscript

Dave S’s solution is what I had implemented, rather than my original “join and compare the text” method. Both are inefficient enough that I kept moving that one call around to where I thought I might need it, but it works.