Property array() of DesktopControl

Hi all,

I would like to make an property array ‘myArray()’ populated with several desktopControls of different type (such as ComboBox, CheckBox, textField, Buttons etc…)

if I use:
var myarray() as DesktopControl = Array(ComboBox1, CheckBox1, etc..)
I get an error! Same result if I declare the array as DesktopUIControl, or Object.
But it works if I declare “as Variant”.

I do not understand this, since all controls are part of the big family to DesktopControl. It should work in principle…

Moreover if I do this:

var theArray() as DesktopControl 
theArray.Add(CheckBox1)
theArray.Add(ComboBox1)

then it also work !!!

I am a bit confuse …

The Array function creates an array of the type of the first parameter. I your case this is DesktopComboBox. The array funtion does not “know” about the fact that you want to get a DesktopControl-Array. If there are parameter with different types, array creates avriant-array

1 Like

Thanks a lot Marius!

Sadly it is not so strict, it follows some Xojo rules to find a least common type, and the first item help in this determination, but seems that for objects it just chooses Variants if they differ, so

// Doesn't work, Xojo will assume Variant()
Var arr() As DesktopControl = Array(DesktopControl(Button1), CheckBox1)

// Works, you explicitly cast all types to the same type
Var arr() As DesktopControl = Array(DesktopControl(Button1), _
                                    DesktopControl(CheckBox1))

As I said: If there are parameter with different types, array creates avriant-array

Thanks a lot to all !