System.TypInfo.TPropInfo有两个函数成员(至少在D-XE3中):
function NameFld: TTypeInfoFieldAccessor; inline;
function Tail: PPropInfo; inline;
Run Code Online (Sandbox Code Playgroud)
我找不到他们的任何文档或其使用的任何示例.它们是什么,它们如何使用?(希望有资格作为一个问题.)
NameFld 函数以TTypeInfoFieldAccessor
.
这允许您执行以下操作:
MyPropertyName:= MyPropInfo.NameFld.ToString;
if (PropInfoA.NameFld = PropInfoB.NameFld) then begin
writeln('property names are the same');
end;
Run Code Online (Sandbox Code Playgroud)
TTypeInfoFieldAccessor 在内部将属性名称存储在短字符串中。
由于 NextGen 编译器不支持短字符串,因此PByte
使用类型。
(我猜作者不想用 ifdefs 乱扔源代码并删除 PShortstring 引用)
输入Tail
是一个PByte,指向内部短字符串的长度字段。
这是 tail 的源代码。
function TTypeInfoFieldAccessor.Tail: PByte;
begin
Result:=
FData //Start of the shortstring
+ FData^ + //Length of the stringData
+ 1; //Add one for the length byte itself
end;
Run Code Online (Sandbox Code Playgroud)
因为短字符串不是以 null 结尾的,所以您不能执行简单的“循环直到找到 null 字符”类型的循环。
因此,可以采用从头到尾的循环将短字符串转换为正常字符串。
奇怪的是,在实际的 RTL 源代码中,到处都使用长度字节而不是函数tail
;所以它看起来像剩菜。
包含一个size
函数并删除tail
.