From Xojo Documentation
|You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!|
Used to overload the intrinsic comparison operators, providing custom functionality.
If Operator_Compare is defined, it is called whenever any of the comparison operators are used to compare the Self instance of the class with another instance. The following comparison operators are covered: =, <, >, <=, >=, <>.
Operator_Compare returns an integer whose meaning is as follows: <0 means that Self is less than the passed parameter, 0 means that Self is equal to the passed parameter, and >0 means that Self is greater than the passed parameter.
This example defines a comparison between two Vectors which have been declared with integer properties x and y (See Operator_Add for a description of the Vector class). The function compares the square lengths of the vectors and then reports on which one is longer.
Var a, b As Integer
a = Self.x ^ 2 + Self.y ^ 2
b = rhs.x ^ 2 + rhs.y ^ 2
If a > b Then Return 1
If a = b Then Return 0
If a < b Then Return -1