⊙ GetTypeData 函数
==============================================================
GetTypeData 函数根据 TTypeInfo 指针获得 TTypeData 的地址。
function GetTypeData(TypeInfo: PTypeInfo): PTypeData;
asm
XOR EDX,EDX ; EDX 清零
MOV DL,[EAX].TTypeInfo.Name.Byte[0] ; 获得 Name 字符串长度
LEA EAX,[EAX].TTypeInfo.Name[EDX+1] ; 获得 TTypeData 的地址
end;
==============================================================
⊙ GetPropInfo 函数
==============================================================
GetPropInfo 函数用于获得属性的 RTTI 指针 PPropInfo。它有四种重载形式,后面三种重载的实现都是调用第一种形式。AKinds 参数用于限制属性的类型,如果得到的 PPropInfo 不属于指定的类型,则返回 nil。
function GetPropInfo(TypeInfo: PTypeInfo; const PropName: string): PPropInfo;
function GetPropInfo(Instance: TObject; const PropName: string;
AKinds: TTypeKinds = []): PPropInfo;
function GetPropInfo(AClass: TClass; const PropName: string;
AKinds: TTypeKinds = []): PPropInfo;
function GetPropInfo(TypeInfo: PTypeInfo; const PropName: string;
AKinds: TTypeKinds): PPropInfo;
==============================================================
⊙ FindPropInfo 函数
==============================================================
FindPropInfo 函数根据属性名称获得属性的 RTTI 指针,它只是在 GetPropInfo 函数的基础上加上了错误检查功能,如果没有属性 RTTI 信息,则触发 EPropertyError 异常。
function FindPropInfo(Instance: TObject; const PropName: string): PPropInfo;
function FindPropInfo(AClass: TClass; const PropName: string): PPropInfo;
==============================================================
⊙ GetPropInfos 函数
==============================================================
GetPropInfos 函数的功能是把一个类(class)所有属性 RTTI 指针 PPropInfo 填充至传入的参数 PPropList 数组中。
注意:这个函数不负责分配该数组的内容,使用前必须根据属性的数量分配足够的空间。该数组结束后必须清除分配的内容。
procedure GetPropInfos(TypeInfo: PTypeInfo; PropList: PPropList);
注:使用 GetPropList 实现相同的功能更方便。
==============================================================
⊙ SortPropList 函数
==============================================================
SortPropList 可以对 GetPropInfos 函数填充的属性信息指针数组按属性名称排序。
procedure SortPropList(PropList: PPropList; PropCount: Integer);
在 VCL 中 SortPropList 只被 GetPropList 函数使用。
==============================================================
⊙ GetPropList 函数
==============================================================
GetPropList 函数同 GetPropInfos 一样,填充 PPropList 数组。GetPropList 实际上是调用 GetPropInfos 进行填充工作,最后返回已填充的属性的数量。
function GetPropList(TypeInfo: PTypeInfo; TypeKinds: TTypeKinds;
PropList: PPropList; SortList: Boolean): Integer;
function GetPropList(TypeInfo: PTypeInfo; out PropList: PPropList): Integer;
function GetPropList(AObject: TObject; out PropList: PPropList): Integer;
注意:GetPropList 的内存分配有点混乱,上面第一个 GetPropList 必须自己分配 PPrpList 数组的内存,后面二个 GetPropList 会自动分配 PPropList 数组的内存。造成这种情况的原因是:第一个 GetPropList 可以设置 TypeKinds 参数限制只返回指定类型的属性,这样就不能直接得到可能返回的属性数量。TypeKinds 参数可以设置为 tkAny,表示返回所有数据类型的属性。
第一个 GetPropList 函数可以设置 SortList 参数对属性名称进行排序。它实际上是调用第二个 GetPropList 并调用 SortPropList 函数执行排序。
注意:PPropList 不再使用的时候,要记得使用 FreeMem 函数清除数组内存(根据返回值是否大于1)。
==============================================上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页