动态数组的 TypeData 中的不同元素类型条目有何作用?
包含不同数据类型的 RTTI 的 TTypeData 字段对于动态数组具有三种不同的元素类型值:
elType: PPTypeInfo; // nil if type does not require cleanup
elType2: PPTypeInfo; // independent of cleanup
DynArrElType: PPTypeInfo; // actual element type, even if dynamic array
elType
的用途非常明确:它由 RTL 中的 FinalizeArray
使用,如果没有什么需要最终确定,则保留nil。但是我们还有另外两个元素,elType2
和 DynArrElType
。有谁知道为什么有两个以及它们两个之间有什么区别?
The TTypeData field containing RTTI for different data types has three different element type values for a dynamic array:
elType: PPTypeInfo; // nil if type does not require cleanup
elType2: PPTypeInfo; // independent of cleanup
DynArrElType: PPTypeInfo; // actual element type, even if dynamic array
The purpose of elType
is pretty clear: it's used by FinalizeArray
in the RTL, and left nil if there's nothing to finalize. But then we have two other elements, elType2
and DynArrElType
. Does anyone know why there are two and what the difference between the two of them is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只能回答关于 elType2 的问题,因为这是我过去使用的唯一一个,该字段用于保存数组的元素类型。检查此示例
这将返回 TDateTime ,它是
TDateArray
类型的元素类型。顺便说一句,在最新版本的 delphi 中,
DynArrElType
字段已被DynUnitName: ShortStringBase
替换Only can answer the question about
elType2
because is the only one which I use in the past, that field is for holding the element type of an array. check this sampleThis will return TDateTime ,which is the type of the elements of the
TDateArray
type.BTW, the
DynArrElType
field was replaced in the last versions of delphi byDynUnitName: ShortStringBase
据我所知,RTL 并未将 elType2 和 DynArrElType 用于任何用途。编译器可能会发出这些值作为额外的元数据,可能用于文档生成器等。
As far as I can tell,
elType2
andDynArrElType
are not used by the RTL for anything. The compiler may be emitting those values just as extra metadata, maybe for documentation generators or the like.