uses System.Math;
type
TPoint = class
public
X, Y: Double;
constructor Create(AX, AY: Double);
end;
TPointHelper = class helper for TPoint
//type method added by the helper
class function GetDistance(
P1, P2: TPoint): Double; static;
end;
constructor TPoint.Create(AX, AY: Double);
begin
X := AX;
Y := AY;
end;
class function TPointHelper.GetDistance(
P1, P2: TPoint): Double;
begin
Result := Sqrt(Power(P1.X - P2.X, 2) +
Power(P1.Y - P2.Y, 2));
end;
var
P1, P2: TPoint;
begin
P1 := TPoint.Create(1, 2);
P2 := TPoint.Create(2, 3);
WriteLn('distance is ',
TPoint.GetDistance(P1, P2):0:4);
//distance is 1.4142
end.