DelphiXE2泛型判断基本类型

uses TypInfo;

procedure TForm1.CheckType<T>;
var
  p: PTypeInfo;
begin
  p := System.TypeInfo(T);
  case p.Kind of
    tkInteger, tkInt64:
    begin
      case GetTypeData(p).OrdType of
        otSByte: ShowMessage('SByte');
        otUByte: ShowMessage('UByte');
        otSWord: ShowMessage('SWord');
        otUWord: ShowMessage('UWord');
        otSLong: ShowMessage('SLong');
        otULong: ShowMessage('ULong');
      end;
    end;
    tkFloat:
    begin
      case GetTypeData(p).FloatType of
        ftSingle: ShowMessage('Single');
        ftDouble: ShowMessage('Double');
        ftExtended: ShowMessage('Extended');
        ftComp : ShowMessage('Comp');
        ftCurr: ShowMessage('Curr');
      end;
    end;
    tkChar: ShowMessage('Char');
    tkWChar: ShowMessage('WChar');

    tkEnumeration: ShowMessage('Boolean');//枚举类型或Boolean类型,需要加以区分
  end;
end;

你可能感兴趣的:(DelphiXE2泛型判断基本类型)