Identity and Equality

Hi, how does Xojo handle identity and equality?

Does Xojo support multiple pointers to an object? So in the code below are a and b considered identical by Xojo? If so, is there an operator to determine identity?

dim a as new Dictionary
dim b as Dictionary = a

For equality I can see that data types (numbers, strings, etc.) support equality comparisons and also from the docs that any class can implement Operator_Compare for custom equality comparisons, but what about other built-in classes. For example can I compare two Dictionaries?..

dim a as new Dictionary
a.value(1) = "one"
a.value(2) = "two"

dim b as new Dictionary
b.value(1) = "one"
b.value(2) = "two"

Does Xojo consider these equal? If so, how deep does it go?

Many thanks for any help.

Why don’t you code
If a = b then
Break
Else
Break
End if
and see where it breaks?
:slight_smile:

Hi Jym, thanks for the quick reply, I really appreciate it!

I was asking more about how Xojo works rather than what would happen in my example.

I could observe what happens in code, but I would have to write a test case for every data type / class to get a full understanding and I would also be no clearer on identity.

[quote=114581:@Chris Copleston]Hi, how does Xojo handle identity and equality?

Does Xojo support multiple pointers to an object?[/quote]

Yes.

Yes.

The Is operator.

Unless explicitly documented, it’s safe to assume that framework classes do not implement Operator_Compare.

Not as such. You would have to define your own function to compare two dictionaries according to whatever criteria you’re interested in.

Thanks Joe, that’s exactly what I was after.