if myArray IsA myType() then

Have a peek at old plugin SDKs and I think you’ll find that arrays have been “object like” for a long time (if not since day 1)
None of whats been discussed on this thread is new to any recent release - its been this way for a very long time
It shouldn’t be surprising to someone who has been writing plugins for as many years as you have

In older SDK’s, years and years ago, using arrays in the plugin and locking or unlocking them was through an undocumented resolver string. Since Joe became a member of Xojo he only sanctioned some resolver strings, but not for arrays. It was only for the last years we knew from Joe that a REALarray is an object. So forgive my ignorance. Nonetheless, how would you solve the issue I brought up without introspection and without an auto type?

Arrays have always been “object like” - whether this was or wasn’t widely known I dont recall (I’ve been here long enough and knew engineers before working here so I’ve known this was the case for a long time)

Still , Isa has never worked nor would I ever have expected it to

Introspection IS the only way I know of to get this info because arrays of items are not types in and of themselves
It IS the way I would solve this as Isa will not work

My comment is on the original question of why doesn’t “isa Array” work
It doesn’t because its not supposed to

And lord knows what you do with an array of variants that actually hold different types (strings, integers, and maybe an array of something else)
Not sure how you would deal with “isA” then since you’d have a list of types for the array elements

Norm, thanks for all the comments. I stand corrected. For the record, I do like Kem’s solution. It is so elegant, never thought of using the auto implementation.

There is an error in the code:

[quote=326422:@Alfred Van Hoek]Got it:

if v.IsArray and w.IsArray and _ v.ArrayElementType = w.ArrayElementType and _ // this line does not make sense v.ArrayElementType = Variant.TypeObject then ...[/quote]
It should probably be:

if v.IsArray and w.IsArray and _ w.ArrayElementType = Variant.TypeObject and _ v.ArrayElementType = Variant.TypeObject then ...

Either way works.

Yes, you’re right. Sorry.

Sorry guys I’m lost on this one. The original post has the line

if varray(0) = warray(0) then return true

which to me means the pointer of the object varray(0) = the pointer of the object warray(0).

Whether they are the same object is irrelevant? They can’t be a pointer to the same object if they aren’t the same? So we only need to know they are objects rather than what type of object?

This trouble shown in the first post is the result of a badly defined language. (Be that Xojo or Visual BASIC, after which it was modeled)

If there were a way to define types, such as “type StringArray as String()”, then you’d be able to use “if w isA StringArray”.
Even without that, the compiler should still always be able to accept “()” after a type name, as parens can have no other meaning at that point - then your original code would compile as well.

Another example where the language design is lacking is when you try to access array elements returned by a function. Consider this:

function returnStrings() as String()

Now try to access an element of it:

dim firstElem as String = returnStrings()(0)

This does not compile but should, if the compiler was a bit smarter. (Actually, the fault is in the language syntax definition, which has never been even published).

So would not

[code]function CompareArrays(v as Variant, w as Variant) as Boolean
if v.IsArray _
And w.IsArray
And varray.ubound > -1 _
And warray.ubound > -1 _
And varray(0) Isa Object _
And warray(0) Isa Object _
And varray(0) = warray(0) then
return true
end if

return false
end function[/code]

work?

I don’t really see why v or w should/would be arrays when only element 0 is being compared.

@Thomas Tempelmann thanks for your reply and given the scope of the players in this thread, I know I’m missing something. Perhaps I’m not purest enough for this type of conversation.

Wait, where did varray and warray come from?

Hey Kem,

Yes you’re right.

[code]function CompareArrays(v as Variant, w as Variant) as Boolean
if v.IsArray _
And w.IsArray
And v.ubound > -1 _
And w.ubound > -1 _
And v(0) Isa Object _
And w(0) Isa Object _
And v(0) = w(0) then
return true
end if

return false
end function[/code]

Didn’t update the original code correctly. Of course the function name CompareArrays implies that both the v & w parameters are arrays, but one should check.

A variant doesn’t have a Ubound property nor can you access it by index.

Ok I’m totally off the picture, but thanks for your reply.

Try to compile and test your code with various types of values (arrays of various types and non-arrays) and I think this will become much clearer.

You hit it right on. The compiler should not tell you that the “Then” keyword is missing. Based on your comments, I think this is a bug. Then the feature request (after fixing this error of the compiler) is to validate " if myArray IsA myType() then ". Given you can define a method like “Untitled as String()” and that is correctly seem as a String array.

Note that there are problems anyway with arrays, like <https://xojo.com/issue/47593>. Am wondering if the issue here is related to the quoted feedback.

It’s only a bug if RS / Xojo Inc had ever specified the language properly, which they didn’t. Their “spec” is defined by the way it actually works. There are more such issues with the compiler, long known, and even they didn’t ever get addressed or even understood (such as the Byref now allowing qualified names such as “obj.value”), so don’t get your hopes up.