if myArray IsA myType() then

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!).

To know if an array is typed to hold class instances:

If  v.ArrayElementType = Variant.TypeObject ...

To know to which class the array is typed to use introspection.

[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

This will not work, as v and w are both holding arrays on this line.

OK.

Then

if v(0) isA PluginSegmentClass and w(0) isA PluginSegmentClass then

As far as I understand the LR, at any rate, ISA compares to a single class on the right.

The issue with v(0) is that the array must at least have one element. I tried with v(-1) and got an OutOfBoundException.

This will require some additional testing, and possibly adding an element just for the test if the array is empty, then removing it.

This will not work either. You need to assign the variant to a variable dimmed as (the correct) array to access its elements.

At any rate, I do not think the variant will be a new object. Arrays cannot be copied that way. This has been discussed time and again.

All he is doing is checking that v and w point to the same object.

Grmbl waste of time…

He is comparing arrays, not copying them.

Without Introspection:

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

Yes, those Autos are required.

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.

That is not copying either.

Kem, much appreciated, Eli, thanks for saying all the right things.

[quote=326382:@Kem Tekinay]Without Introspection:

Yes, those Autos are required.[/quote]
Actually, this is more general:

[code]
if v.IsArray and w.IsArray 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]
And works very good. Thanks again!

Ah, I thought you were trying to confirm a particular type within the array.

BTW, your version will crash if the given parameters are, say, String arrays.

I don’t care what you say. I’ll ignore you. You are too much of an annoyance anyway.

Got it:

[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.

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=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.