uses System.Math;
type
TPoint = class
public
X, Y: Double;
constructor Create(AX, AY: Double);
end;
//class helper extends the class
//without touching its source
TPointHelper = class helper for TPoint
function DistanceTo(P: TPoint): Double;
end;
constructor TPoint.Create(AX, AY: Double);
begin
X := AX;
Y := AY;
end;
function TPointHelper.DistanceTo(
P: TPoint): Double;
begin
Result := Sqrt(Power(X - P.X, 2) +
Power(Y - P.Y, 2));
end;
var
P1, P2: TPoint;
begin
P1 := TPoint.Create(1, 2);
P2 := TPoint.Create(2, 3);
WriteLn('distance is ',
P1.DistanceTo(P2):0:4);
//distance is 1.4142
end.