首页 > 其他 > 详细

类型与泛型标记

时间:2015-03-28 11:27:47      阅读:201      评论:0      收藏:0      [点我收藏+]

uses System.TypInfo;

 

  // Sync with compiler internals
  TTypeKind = (tkUnknown, tkInteger, tkChar, tkEnumeration, tkFloat,
    tkString, tkSet, tkClass, tkMethod, tkWChar, tkLString, tkWString,
    tkVariant, tkArray, tkRecord, tkInterface, tkInt64, tkDynArray, tkUString,
    tkClassRef, tkPointer, tkProcedure {, tkMRecord});

type
{$IFDEF NEXTGEN}
  TSymbolName = Byte;
{$ELSE  NEXTGEN}
  TSymbolNameBase = string[255];
  TSymbolName = type TSymbolNameBase;
{$ENDIF NEXTGEN}

 

  TTypeInfoFieldAccessor = record
  strict private                   //静态?私有
    FData: PByte;
  public
    procedure SetData(const Data: PByte); inline;
    class operator Equal(const Left, Right: TTypeInfoFieldAccessor): Boolean; inline;
    function UTF8Length: integer; inline;
    function ToString: string;
{$IFNDEF NEXTGEN}
    function ToShortUTF8String: ShortString; inline;
{$ENDIF !NEXTGEN}
    function ToByteArray: TBytes;
    function Tail: PByte; inline;
  end;

-------------------TypeInfo (T)-------------------

  PTypeInfo = ^TTypeInfo;
  TTypeInfo = record
    Kind: TTypeKind;
    Name: TSymbolName;
    function NameFld: TTypeInfoFieldAccessor; inline;
   {TypeData: TTypeData}
    function TypeData: PTypeData; inline;
  end;

 

function TSampleClass<T>.GetDataName: string;
var
 Kind: TTypeKind;
begin
  Result := GetTypeName (TypeInfo (T));
  Kind := PTypeInfo(TypeInfo(T))^.Kind;
  case Kind of
    tkInteger: ShowMessage(‘I‘);
    tkFloat: ShowMessage(‘F‘);
    tkString,tkUString: ShowMessage(‘S‘);
    tkChar:   ShowMessage(‘C‘);
    tkClass:  ShowMessage(‘Class‘);
    else ShowMessage(Result);
  end;
end;

类型与泛型标记

原文:http://www.cnblogs.com/ZhouXiHong/p/4373900.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!