控制流 / 条件语句 / switch/case 语句

uses System.TypInfo;

type
  TPoint<T> = record
    X, Y: T;
    //standalone generic functions are
    //not allowed: a method of the
    //generic record; matching by TypeInfo
    function Describe: string;
  end;

function TPoint<T>.Describestring;
begin
  if TypeInfo(T) = TypeInfo(Integerthen
    Result := 'Point (int, int)'
  else if TypeInfo(T) = TypeInfo(Doublethen
    Result := 'Point (float, float)'
  else
    Result := 'Unknown';
end;

var
  P1TPoint<Integer>;
  P2TPoint<Double>;
begin
  P1.X := 3;
  P1.Y := 4;
  WriteLn('desc1 is 'P1.Describe);
  //desc1 is Point (int, int)

  P2.X := 7.1;
  P2.Y := 4.6;
  WriteLn('desc2 is 'P2.Describe);
  //desc2 is Point (float, float)
end.