TPropInfo的未记录成员 [英] Undocumented Members of TPropInfo

查看:67
本文介绍了TPropInfo的未记录成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.TypInfo.TPropInfo具有两个函数成员(至少在D-XE3中):

System.TypInfo.TPropInfo has two function members (at least in D-XE3):

function NameFld: TTypeInfoFieldAccessor; inline;
function Tail: PPropInfo; inline;

我找不到任何有关它们的文档或使用示例。它们是干什么的,如何使用? (希望成为一个问题。)

I cannot find any documentation for them or any examples of their use. What are they for and how can they be used? (Hope that qualifies as one question.)

推荐答案

NameFld函数将属性名称返回为 TTypeInfoFieldAccessor

The NameFld function returns the name of a property as a TTypeInfoFieldAccessor.

这允许您执行以下操作:

This allows you to do the following:

MyPropertyName:= MyPropInfo.NameFld.ToString;
if (PropInfoA.NameFld = PropInfoB.NameFld) then begin 
  writeln('property names are the same');
end;

TTypeInfoFieldAccessor将属性的名称存储在 shortstring 内部。

因为NextGen编译器不支持shortstring,所以使用PByte 类型。

(我想作者不想用ifdefs乱扔源代码并撕掉PShortstring引用)

The TTypeInfoFieldAccessor stores the name of a property in a shortstring internally.
Because the NextGen compiler does not support shortstrings, a PByte type is used.
(I guess the author did not want to litter the source with ifdefs and ripped out the PShortstring references)

Tail 的输入是一个指向内部短字符串长度字段的PByte。

The input of Tail is a PByte pointing to length field of the internal shortstring.

这是tail的源代码。

Here's the source code for 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;

由于短字符串不是以null终止的,因此您无法执行简单的循环,直到找到null字符

因此可以使用从头到尾的循环将短字符串转换为普通字符串。

在实际的RTL源代码中,足够奇怪的是,在所有地方都使用了长度字节 tail 函数的;因此看起来像是剩菜了。

包括 size 函数并剔除 tail

Because shortstrings are not null terminated, you cannot do a simple "loop until the null char is found" kind of loop.
Therefore a loop from start to tail can employed to transfer the shortstring into a normal string.
Strangely enough in the actual RTL sourcecode the length byte is used everywhere instead of the tail function; so it looks like a leftover.
It would have made more sense to include a size function and rip out the tail.

这篇关于TPropInfo的未记录成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆