PTypeData = ^TTypeData;
TTypeData = packed record
case TTypeKind of
tkUnknown, tkLString, tkWString, tkVariant: ();
tkInteger, tkChar, tkEnumeration, tkSet, tkWChar: (
OrdType: TOrdType;
case TTypeKind of
tkInteger, tkChar, tkEnumeration, tkWChar: (
MinValue: Longint;
MaxValue: Longint;
case TTypeKind of
tkInteger, tkChar, tkWChar: ();
tkEnumeration: (
BaseType: PPTypeInfo;
NameList: ShortStringBase;
EnumUnitName: ShortStringBase));
tkSet: (
CompType: PPTypeInfo));
tkFloat: (
FloatType: TFloatType);
tkString: (
MaxLength: Byte);
tkClass: (
ClassType: TClass;
ParentInfo: PPTypeInfo;
PropCount: SmallInt;
UnitName: ShortStringBase;
{PropData: TPropData});
tkMethod: (
MethodKind: TMethodKind;
ParamCount: Byte;
ParamList: array[0..1023] of Char
{ParamList: array[1..ParamCount] of
record
Flags: TParamFlags;
ParamName: ShortString;
TypeName: ShortString;
end;
ResultType: ShortString});
tkInterface: (
IntfParent : PPTypeInfo; { ancestor }
IntfFlags : TIntfFlagsBase;
Guid : TGUID;
IntfUnit : ShortStringBase;
{PropData: TPropData});
tkInt64: (
MinInt64Value, MaxInt64Value: Int64);
tkDynArray: (
elSize: Longint;
elType: PPTypeInfo; // nil if type does not require cleanup
varType: Integer; // Ole Automation varType equivalent
elType2: PPTypeInfo; // independent of cleanup
DynUnitName: ShortStringBase);
end;
请详细解释一下每一行的代码,非常感谢!
解释完后,马上给分!
TTypeData = packed record
case TTypeKind of
tkUnknown, tkLString, tkWString, tkVariant: ();
tkInteger, tkChar, tkEnumeration, tkSet, tkWChar: (
OrdType: TOrdType;
case TTypeKind of
tkInteger, tkChar, tkEnumeration, tkWChar: (
MinValue: Longint;
MaxValue: Longint;
case TTypeKind of
tkInteger, tkChar, tkWChar: ();
tkEnumeration: (
BaseType: PPTypeInfo;
NameList: ShortStringBase;
EnumUnitName: ShortStringBase));
tkSet: (
CompType: PPTypeInfo));
tkFloat: (
FloatType: TFloatType);
tkString: (
MaxLength: Byte);
tkClass: (
ClassType: TClass;
ParentInfo: PPTypeInfo;
PropCount: SmallInt;
UnitName: ShortStringBase;
{PropData: TPropData});
tkMethod: (
MethodKind: TMethodKind;
ParamCount: Byte;
ParamList: array[0..1023] of Char
{ParamList: array[1..ParamCount] of
record
Flags: TParamFlags;
ParamName: ShortString;
TypeName: ShortString;
end;
ResultType: ShortString});
tkInterface: (
IntfParent : PPTypeInfo; { ancestor }
IntfFlags : TIntfFlagsBase;
Guid : TGUID;
IntfUnit : ShortStringBase;
{PropData: TPropData});
tkInt64: (
MinInt64Value, MaxInt64Value: Int64);
tkDynArray: (
elSize: Longint;
elType: PPTypeInfo; // nil if type does not require cleanup
varType: Integer; // Ole Automation varType equivalent
elType2: PPTypeInfo; // independent of cleanup
DynUnitName: ShortStringBase);
end;
请详细解释一下每一行的代码,非常感谢!
解释完后,马上给分!
TTypeKind = (tkUnknown, tkInteger, tkChar, tkEnumeration, tkFloat,
tkString, tkSet, tkClass, tkMethod, tkWChar, tkLString, tkWString,
tkVariant, tkArray, tkRecord, tkInterface, tkInt64, tkDynArray);
TTypeInfo记录的第一个域即存类型类别,第二个则用来存放类型的名称,而第三个域则是用来存放附加数据类型内容的。而具体的附加数据类型内容就是定义在TTypeData记录中的。关于这个记录的详细内容如下注释所示:PTypeData = ^TTypeData; //定义记录指针PTypeData,Delphi中这种定义方式很常见。
//而定义的目的就是操作指针要比操作具体的记录要快;
TTypeData = packed record //申明存放附加数据类型的记录TTypeData
case TTypeKind of //依据数据类型的不同定义不同的附加数据类型结构
tkUnknown, tkLString, tkWString, tkVariant: (); //暂时无定义,即表明无相
//关附加数据类型
tkInteger, tkChar, tkEnumeration, tkSet, tkWChar: (
OrdType: TOrdType; //此5中数据类型均为有序类型,TOrdType可以是如下
//值:otSByte, otUByte, otSWord, otUWord,
// otSLong, otULong
case TTypeKind of //再进行细分,将tkSet视作单独一类
tkInteger, tkChar, tkEnumeration, tkWChar: (
MinValue: Longint; //定义最小值
MaxValue: Longint; //定义最大值
case TTypeKind of //第二次进行细分
tkInteger, tkChar, tkWChar: (); //无其他附加类型信息
//如果是枚举类型则包含:
//基本元素类型BaseType
//名称列表和枚举单元名称,均是长度为256
//具体枚举单元名称里面存放的啥东西俺也不清楚,你自己写
//个小程序实验实验吧!
tkEnumeration: (
BaseType: PPTypeInfo;
NameList: ShortStringBase;
EnumUnitName: ShortStringBase));
//如果有序类型是集合类型则仅包含一个域CompType,但我不知道这个域
//里面放着啥东西,没的办法,只能做实验!
tkSet: (
CompType: PPTypeInfo));
//浮点类型指明其子类型,可以是:ftSingle, ftDouble, ftExtended, ftComp, ftCurr
tkFloat: (
FloatType: TFloatType);
//字串类型指明其最大长度
tkString: (
MaxLength: Byte);
//类类型包含内容比较多
tkClass: (
ClassType: TClass; //类引用
ParentInfo: PPTypeInfo; //父类指针
PropCount: SmallInt; //属性数量,注意:这里只是Published部分申明的属性数量
UnitName: ShortStringBase; //申明单元名称,长度为256
{PropData: TPropData}); //公布的属性信息
//TPropData记录中记录了公布属性的数量和属性列表
//属性列表实为一记录数组,数据元素数据类型
//为TPropInfo,其中此记录中详细记录了:属性类型、
//读写存储方法的指针、索引、默认值、名字索引和
//属性名称
//方法类型
tkMethod: (
MethodKind: TMethodKind; //方法类型子类,可以是:mkProcedure, mkFunction,
//mkConstructor, mkDestructor,mkClassProcedure,
//mkClassFunction,mkSafeProcedure, mkSafeFunction
ParamCount: Byte; //参数数量
ParamList: array[0..1023] of Char //参数名称列表
//参数名称列表实际上也是一个记录数组,其中记录包含了参数名称,类型名称,
//和参数类别信息----参数类别信息可以是:pfVar, pfConst, pfArray,
//pfAddress, pfReference, pfOut这些元素组成的集合
{ParamList: array[1..ParamCount] of
record
Flags: TParamFlags;
ParamName: ShortString;
TypeName: ShortString;
end;
ResultType: ShortString}); //方法的返回值类型名称
//接口类型,基本同tkClass类别
tkInterface: (
IntfParent : PPTypeInfo; { ancestor }
IntfFlags : TIntfFlagsBase;
Guid : TGUID; //全局统一标识符信息
IntfUnit : ShortStringBase;
{PropData: TPropData});
tkInt64: (
MinInt64Value, MaxInt64Value: Int64); //有符号的64位的整型的范围信息
//动态数组:以前版本(忘记是哪个版本了!)中动态数组这里是没有附加类型信息的
tkDynArray: (
elSize: Longint; //数组长度
elType: PPTypeInfo; // nil if type does not require cleanup
varType: Integer; // Ole Automation varType equivalent
elType2: PPTypeInfo; // independent of cleanup
//申明单元的名称
DynUnitName: ShortStringBase);
end;好了,内容就这么多了,只要记住一点:附加类型信息是对类型的描述信息,而RTTI中最主要的信息也就来源于附加类型信息记录。Delphi的IDE的信息提示功能的数据来源也缘于此!