[quote=464832:@Paul Lefebvre]Would introspection work? Perhaps something like this:
[code]Dim V As Variant
Dim PA() As Picture
V = PA
Dim myType As Introspection.TypeInfo = Introspection.GetType(V)
Dim typeName As String = myType.FullName // Picture() in this case[/code][/quote]
Thanks
That could work for some cases and I may need to use it, but I suspect it would have more overheard and I want this to be fast as it could get called a lot…
I have not used introspection so I may be wrong but it seems to me this would also be a more limited solution because subclasses would have to be explicitly considered when for an IsA they would not need to be… So in general a workaround that can work but less maintainable.
Is the TypeMismatchException a bug, or was this case just not considered when the complier was worked on?
Is it worth a bug report or feature request?
Basically I’m asking is there a reasonable chance at all this might be addressed at some point… if not I won’t bother…
Logically one would expect it to work, but given everything else I am not sure if this relatively obscure case realistically would ever get addressed.
If V.Type - 4096 = Variant.TypeObject Then
Dim OA() As Object
OA = V ' Why TypeMismatchException?
End if
the array members are not compatible without casting each one
so you end up having to walk the elements and cast each one to put them in the other array
[quote=464884:@Norman Palardy]
If V.Type - 4096 = Variant.TypeObject Then
Dim OA() As Object
OA = V ' Why TypeMismatchException?
End if
the array members are not compatible without casting each one
so you end up having to walk the elements and cast each one to put them in the other array[/quote]
But how do you access them?
V is not an array, but contains an array… Without assigning the contents of V to an array variable how can you get at the elements?
[quote=464893:@Norman Palardy]
But this isnt new
This has been this way for a decade or more
And one reason I try to never use variants as they cant always be unboxed correctly[/quote]
I usually try to avoid variants when I can, but I don’t see how to for what I want to do in this case.
As I don’t use them much, this is the first time I have run across this issue… What I tried logically should work and in an ideal world where Xojo was more complete it would… but I suspect this never will as I think they would need a complier person on staff for that to happen
Paul’s suggestion is a workaround I can use in this case, but it’s not an ideal solution. Having an way to get isA to work for array object type in a variant would be.
the other option would be to create your own “variant” like type that you can control & store more info about and use that for these cases instead of trying to use variants which dont seem to help you out as much
and you could add operator_convert methods to it to make your initial code work the way you expect
Following code achieves what you are trying to do:
dim p() as picture
p.append new picture(1,1,32)
dim v as variant = p
dim a as auto = v
dim b() as object = a
select case b(0)
case isa picture
//handle picture
end select
End Sub