动态数组的 TypeData 中的不同元素类型条目有何作用?

发布于 2024-12-19 10:16:22 字数 472 浏览 4 评论 0原文

包含不同数据类型的 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。但是我们还有另外两个元素,elType2DynArrElType。有谁知道为什么有两个以及它们两个之间有什么区别?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水中月 2024-12-26 10:16:22

只能回答关于 elType2 的问题,因为这是我过去使用的唯一一个,该字段用于保存数组的元素类型。检查此示例

{$APPTYPE CONSOLE}

uses
  TypInfo,
  SysUtils;

type
 TDateArray = array of TDateTime;
Var
  p      : PPTypeInfo;
begin
  try
     p:=TypInfo.GetTypeData(TypeInfo(TDateArray)).elType2;
     Writeln(TypInfo.GetTypeName(p^));
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.

这将返回 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 sample

{$APPTYPE CONSOLE}

uses
  TypInfo,
  SysUtils;

type
 TDateArray = array of TDateTime;
Var
  p      : PPTypeInfo;
begin
  try
     p:=TypInfo.GetTypeData(TypeInfo(TDateArray)).elType2;
     Writeln(TypInfo.GetTypeName(p^));
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.

This 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 by DynUnitName: ShortStringBase

无需解释 2024-12-26 10:16:22

据我所知,RTL 并未将 elType2 和 DynArrElType 用于任何用途。编译器可能会发出这些值作为额外的元数据,可能用于文档生成器等。

As far as I can tell, elType2 and DynArrElType 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文