运算符重载

uses System.Math;

type
  TPoint = record
    X, Y: Integer;
    constructor Create(AXAYInteger);
    //new operators cannot be invented:
    //an existing one gets a new meaning
    class operator BitwiseXor(const P: TPoint;
      Power: Integer): TPoint;
  end;

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

class operator TPoint.BitwiseXor(
  const P: TPoint; Power: Integer): TPoint;
begin
  Result := TPoint.Create(
    Round(System.Math.Power(P.X, Power)),
    Round(System.Math.Power(P.Y, Power)));
end;

var
  P1TPoint;
begin
  P1 := TPoint.Create(23);

  P1 := P1 xor 3;
  //p1.X is 8 and p1.Y is 27

  WriteLn('x = 'P1.X', y = 'P1.Y);
end.