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>.AsText: string;
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(5, 8);
WriteLn('textInt is ', SizeInt.AsText);
//textInt is [5; 8]
SizeFloat := TSize<Double>.Create(3.7, 1.58);
WriteLn('textFloat is ', SizeFloat.AsText);
//textFloat is [3.7; 1.58]
end.