Обобщенные типы

uses System.SysUtils, System.Rtti;

type
  TSize<T> = class
  private
    FWidth, FHeight: T;
  public
    constructor Create(const AWidth,
      AHeight: T);
    function AsText: string;
  end;

constructor TSize<T>.Create(
  const AWidth, AHeight: T);
begin
  FWidth := AWidth;
  FHeight := AHeight;
end;

function TSize<T>.AsTextstring;
begin
  //TValue turns any T into text
  Result := Format('[%s; %s]',
    [TValue.From<T>(FWidth).ToString,
     TValue.From<T>(FHeight).ToString]);
end;

var
  SizeInt: TSize<Integer>;
  SizeFloat: TSize<Double>;
begin
  SizeInt := TSize<Integer>.Create(58);
  WriteLn('textInt is ', SizeInt.AsText);
  //textInt is [5; 8]

  SizeFloat := TSize<Double>.Create(3.71.58);
  WriteLn('textFloat is ', SizeFloat.AsText);
  //textFloat is [3.7; 1.58]
end.