overloading operator <

  1. last year

    Brian O

    11 Oct 2017 Pre-Release Testers, Xojo Pro Calgary, AB

    I am trying to overload operator compare.
    however the right hand side is nil.
    what does one do in operator compare if the right hand side is nil?
    throw an exception?
    throw or raise?

  2. Dave S

    11 Oct 2017 San Diego, California USA

    a value is never < or > nil
    it is = Nil or <> Nil

    so you would need to make that check BEFORE you attempt < or >

  3. Kem T

    11 Oct 2017 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    It will send Nil to your Operator_Compare and you should return 1 or -1 depending on how you'd want it sorted, if you care.

    Function Operator_Compare (other As MyClass) As Integer
      if other is nil then
        return 1 // or -1
      end if
    End Function

    BTW, this is why I always use o is nil to bypass any custom Operator_Compare, or I make a clear note as to why I want Operator_Compare to do the work.

or Sign Up to reply!