================
⊙ GetObjectPropClass 函数
==============================================================
GetObjectPropClass 函数用于返回对象类型的属性所属的类(class)。
function GetObjectPropClass(Instance: TObject; PropInfo: PPropInfo): TClass;
function GetObjectPropClass(Instance: TObject; const PropName: string): TClass;
function GetObjectPropClass(PropInfo: PPropInfo): TClass;
这个函数被 SetObjectProp 函数使用,用于参数检验。
==============================================================
⊙ PropType / PropIsType 函数
==============================================================
PropType 函数用于获得属性的数据类型。
function PropType(Instance: TObject; const PropName: string): TTypeKind;
function PropType(AClass: TClass; const PropName: string): TTypeKind;
PropIsType 判断属性是否属于某种数据类型。它调用 PropType 实现功能。
function PropIsType(Instance: TObject; const PropName: string;
TypeKind: TTypeKind): Boolean;
function PropIsType(AClass: TClass; const PropName: string;
TypeKind: TTypeKind): Boolean;
==============================================================
⊙ IsPublishedProp 函数
==============================================================
IsPublishedProp 函数用于判断属性是否是 published 属性,它通过检查该属性 RTTI 指针是否等于 nil 来实现功能。
function IsPublishedProp(Instance: TObject; const PropName: string): Boolean;
function IsPublishedProp(AClass: TClass; const PropName: string): Boolean;
IsPublishedProp 函数没有被 VCL 使用。
==============================================================
⊙ IsStoredProp 函数
==============================================================
IsStoredProp 函数使用属性信息中的 TPropInfo.StoredProp 函数指针来调用属性定义时用 stored 关键字定义的函数的结果。
这个函数被用于 Delphi 持续机制,TWriter.WriteProperties 方法调用 IsStoredProp 判断是否需要把该属性的值写入流中。
function IsStoredProp(Instance: TObject; PropInfo: PPropInfo): Boolean;
function IsStoredProp(Instance: TObject; const PropName: string): Boolean;
==============================================================
⊙ FreeAndNilProperties 函数
==============================================================
FreeAndNilProperties 函数用于清除一个对象的所有 published 的对象类型的属性的对象。这个函数调用 GetObjectProp 执行获得对象属性的对象句柄,并调用对象的 Free 方法清除这个对象,然后调用 SetObjectProp 设置该属性为 nil。
procedure FreeAndNilProperties(AObject: TObject);
我不知道这个函数能用在哪里,至少 VCL 中没有使用这个函数。
==============================================================
⊙ SetToString / StringToSet 函数
==============================================================
SetToString 和 StringToSet 是两个 RTTI 辅助函数,它们把集合值转换为字符串,或者把字符串转换为集合值。
function SetToString(PropInfo: PPropInfo; Value: Integer;
Brackets: Boolean = False): string;
function StringToSet(PropInfo: PPropInfo; const Value: string): Integer;
注意:这里的集合值最多只能包含 32 个元素(4 bytes),这是集合 RTTI 的限制。
==============================================================
⊙ GetEnumName / GetEnumValue / GetEnumNameValue 函数
==============================================================
GetEnumName 函数根据枚举整数值返回枚举字符串。它可以返回以下三种枚举名称:
Integer:直接返回 IntToStr(Integer)
Boolean:返回 True/False
Enum :返回 TTypeData^.NameList 中存储的枚举名称
function GetEnumName(TypeInfo: PTypeInfo; Value: Integer): string;
GetEnumValue 函数根据枚举字符串返回枚举整数值。它与 GetEnumName 类似,可以返回三种枚举的整数值,但对于 Enum 类型,它调用了 GetEnumNameValue 函数。
function GetEnumValue(TypeInfo: PTypeInfo; const Name: string): Integer;
GetEnumNameValue 函数与 GetEnumValue 函数功能差不多,但它是个汇编函数,只能返回纯枚举类型的值。其工作原理也是匹配 TTypeData^.NameList 值。
function GetEnumNameValue(TypeInfo: PTypeInfo; const Name: string): Integer;
注意:GetEnumNameValue 隐藏在 Implementation 段,不能直接使用,它是为 GetEnumValue 函数服务的。
==============================================================
⊙ GetOrdProp 函数详解
==============================================================
GetOrdProp 是 Delphi RTTI 中使用频繁的函数。GetOrdProp 根据对象句柄和对象属性的 TPropInfo 指针获得对象的属性值。它的返回值是 Longint,需要强制转换成相应的属性类型才能使用。
function GetOrdProp(Instance: TObject; PropInfo: PPropInfo): Longint;
GetOrdProp 调用 TPropInfo.GetProc 函数指针得到属性的返回值。它的工作过程是:
如果该属性的类型是 class 类型,那么返回值是 4 个字节(对象句柄)。
否则通过 TTypeData.OrdType 得到返回值的类型,存储在 BL 中。
{ TOrdType = (otSByte, otUByte, otSWord, otUWord, otSLong, otULong); }
检查 TPropInfo.GetProc 的第一个字节(注意是 GetProc 指针的第一个字节):
如果 GetProc[0] = $FF,说明 GetProc 是 field offset;
如果 GetProc[0] = $FE,说明 GetProc 是 virtual method offset;
如果 GetPro上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页