码迷,mamicode.com
首页 > 其他好文 > 详细

类型与泛型标记

时间:2015-03-28 11:30:47      阅读:121      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!