Операторы равенства

Перегрузка операторов

type
  TPoint = record
    X, Y: Integer;
    constructor Create(AX, AY: Integer);
    class operator Equal(
      const L, R: TPoint): Boolean;
    class operator NotEqual(
      const L, R: TPoint): Boolean;
  end;

constructor TPoint.Create(AX, AY: Integer);
begin
  X := AX;
  Y := AY;
end;

class operator TPoint.Equal(
  const L, R: TPoint): Boolean;
begin
  Result := (L.X = R.X) and (L.Y = R.Y);
end;

class operator TPoint.NotEqual(
  const L, R: TPoint): Boolean;
begin
  Result := not (L = R);
end;

var
  P1, P2, P3: TPoint;
begin
  P1 := TPoint.Create(1, 1);
  P2 := TPoint.Create(2, 2);
  P3 := TPoint.Create(1, 1);

  WriteLn('equal1 is ', P1 = P2);
  //equal1 is FALSE

  WriteLn('equal2 is ', P1 = P3);
  //equal2 is TRUE

  WriteLn('equal3 is ', P1 <> P3);
  //equal3 is FALSE
end.