function CompareArrays(v as Variant, w as Variant) as Boolean
if v.IsArray and w.IsArray then
if v isA PluginSegmentClass() and w isA PluginSegmentClass() then <--------------------------
dim varray() as PluginSegmentClass = v
dim warray() as PluginSegmentClass = w
if varray(0) = warray(0) then return true
end if
end if
return false
end function
While this may look okay, the compiler balks at the brackets (see arrow) that defines the type is an array. It says that the keyword then is expected (and it is there!).
[quote=326363:@Alfred Van Hoek][code]
function CompareArrays(v as Variant, w as Variant) as Boolean
if v.IsArray and w.IsArray then
if v isA PluginSegmentClass() and w isA PluginSegmentClass() then <--------------------------
dim varray() as PluginSegmentClass = v
dim warray() as PluginSegmentClass = w
if varray(0) = warray(0) then return true
end if
end if
return false
end function
[/code]
While this may look okay, the compiler balks at the brackets (see arrow) that defines the type is an array. It says that the keyword then is expected (and it is there!).[/quote]
Call me pedant, in programming vocabulary, these are usually called parenthesis : ( ). Brackets are usually this : [ ] and these are braces : { }. Even if all are in the general family of brackets, using the proper semantics is important in a programming language, and to communicate among programmers. The less ambiguity, the less risk of miscommunication.
Incidentally, typographically, they are very different objects as well.
Remove the parenthesis. They have nothing to do as a type. You test against a single class, not an array of classes. http://developer.xojo.com/isa
if v isA PluginSegmentClass and w isA PluginSegmentClass then
Public Function CompareArrays(v as Variant, w As Variant) as Boolean
if v.IsArray and w.IsArray and _
v.ArrayElementType = w.ArrayElementType and _
v.ArrayElementType = Variant.TypeObject then
dim a1 as auto = v
dim a2 as auto = w
dim o1() as object = a1
dim o2() as object = a2
return _
o1.Ubound <> -1 and o2.Ubound <> -1 and _
o1( 0 ) isa PluginSegmentClass and o2( 0 ) isa PluginSegmentClass and _
o1( 0 ) = o2( 0 )
end if
End Function
Indeed, with a copy of v to varray, and w to warray in the process. At any rate that was not what the question was about, and I don’t care discussing ad nauseum anyway.
[code]
if v.IsArray and w.IsArray and _
v.ArrayElementType = w.ArrayElementType and _
v.ArrayElementType = Variant.TypeObject then
dim a1 as auto = v
dim a2 as auto = w
dim o1() as object = a1
dim o2() as object = a2
return _
o1.Ubound <> -1 and o2.Ubound <> -1 and _
o1( 0 ) = o2( 0 )
end if[/code]
I am a bit hesitant here, but I think you shouldn’t have said this. Please stick to the thread. And yes I should have said parenthesis. Further, Eli did say the correct things. Perhaps I should have given a better name for the function, like:
Function ArraysAreEqual(v as Variant, w as Variant) as Boolean
“IsA myType()” is valid as far as I can judge. Kem gave a very nice workaround.
[quote=326432:@Norman Palardy]myType() isn’t a type in and of itself - its “an array of elements of some type”
isA works with types - see http://developer.xojo.com/isa
as for “could isa work with an array” thats a Joe question & I know he’s not around today[/quote]
Ok, you and Michael might be right. The fact that a comparison of arrays can only be done through an auto type is disturbing. Lastly, a REALarray in the plugin SDK is a REALobject and that’s why I believe the syntax shouldn’t lead to a compiler error. The debugger sees the object array in the variant correctly with the correct type. Hopefully Joe can set me straight.