Arrays in dictionaries

Hello

I’m trying to loop over some arrays in a dictionary.
The problem I am facing is get the array back out of the dictionary. Please look at this line of code:

For Each Cobject As RelationalFrames.ContentObject In Array(LinkedObjects.Value(Ex.Name))

Ok, what do we have, I need an Cobject from type RelationalFrames.ContentObject in an array stored in a dictionary with Key “Ex.Name”

The dictionary is filled earlier in the code with this line:

LinkedObjects.Value(o.Name) = o.outputs

Where o.outputs is an array.

But on the first line (the For…Each) I got an illegalCastException on the Array(LinkedObjects.Value(Ex.Name))
Can anyone help me?
Thanks

You cannot cast a Variant to an array directly. You have to first assign LinkedObjects.Value(Ex.Name) to a temp variable and the loop over that variable:

Dim arr() As RelationalFrames.ContentObject = LinkedObjects.Value(Ex.Name) For Each Cobject As RelationalFrames.ContentObject In arr

Stupid of me that I didn’t test that option. Thanks.
Xojo Developers: Is there any reason why it is technically impossible to cast a Variant to an Array?

Thanks

You can only type cast to a class or data type. An array is neither so you cannot cast something to it.

Clever! Didn’t notice that an Array isn’t a class but a keyword.