array questions

How do you get the ubound of each dimension of an multidimensional array?
If you redim an array, must you allocate a new object for each element of that array?
If you destroy an array (redim -1) does the destructors of each element of the array elements get called? (deref)

If you are willing to use the newer version of Xojo

[quote]Arrays.LastRowIndex
Arrays.LastRowIndex(Optional dimension As Integer = 1) As Integer
Returns the row index of the last row of the array. The optional parameter allows you to get the last row index of a specific dimension if the array is multi-dimensional.[/quote]

I don’t have the confidence to publicly pretend to definitively answer the second or third questions. I think I personally have always allocated a new object for each element as I add elements to an array of objects.

[quote=486535:@Brian O’Brien]How do you get the ubound of each dimension of an multidimensional array?
[/quote]
Don’t know. I’ve not used multidimensional arrays for years, I use classes to store multiple properties in a single dimension array.

[quote=486535:@Brian O’Brien]If you redim an array, must you allocate a new object for each element of that array?
[/quote]
Logic dictates that you will need to create a new instance for each element - what if your class only has a constructor that requires a parameter? For an array of an intrinsic data type the objects will be created with their default values.[quote=486535:@Brian O’Brien]If you destroy an array (redim -1) does the destructors of each element of the array elements get called? (deref)[/quote]
Not directly by the ReDim. As the reference count for each object results in zero the object will be destroyed which will invoke the destructor method if it exists. So if the only reference to the object is from the array then yes the object will be destroyed.

Ubound(array1, index, index, …)

Each element will be initialized with the default value for the corresponding type. For an array of objects, the default value is Nil. I usually instantiate elements only when needed.

Its better if you can use a Property class and store that in that specific class Array Type so you can use that. If you need to sort that class based Array then use sortwith. I have also moved away from MD Arrays due to the lack of flexibility.

md arrays and certain other built in type seem great until you hit the boundaries and then you have to revise things

far too often I see people use dictionaries full of variants to pass parameters around their apps
and then they get odd or hard to track bugs
Variants subvert the type checking the compiler can do
It cant help you when you put a string in and later pull that data out as an integer or something else
Using a class you create instead makes it so the compiler CAN help you esp if you use normal types like string , integer etc that it can do type checking on

not being able to define a fully typed dictionary where you can say “all keys are strings and all values are integers” or something like that is, sometimes, a big impediment - again the compiler cant help you so you do things by convention and habit instead of because you designed it to be a specific way

Try and avoid variants as much as possible