如何在Delphi调试期间查看通用tList [英] How to look into generic tList during Delphi debugging

查看:179
本文介绍了如何在Delphi调试期间查看通用tList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Delphi 10.3.1 COMMUNITY版本,在调试项目时无法查看通用的tList.

I use Delphi 10.3.1 COMMUNITY version and can't look into generic tList while I debug the project.

我知道最新版本的Delphi不支持允许查看通用tList的旧式调试功能.因此,我在以下代码中使用了tList.List来评估tList.

I know the latest version of Delphi doesn't support the old-typed debug feature which allows to look into generic tList. So I used tList.List in the following code to evaluate the tList.

tList<tRecord>.List中,我可以查看它,但在tList<Integer>.List中却不能.

In tList<tRecord>.List I can look into it but can't do it in tList<Integer>.List.

type
  tRecord = record
    Field: Integer;
  end;

procedure TForm1.FormCreate(Sender: TObject);
var
  _Record: tRecord;
  _List1: TList<tRecord>;
  _List2: TList<Integer>;
  i: Integer;
begin
  _List1 := TList<tRecord>.Create;
  _List2 := TList<Integer>.Create;

  for i := 0 to 4 do
  begin
    _Record.Field := i;

    _List1.Add(_Record);
    _List2.Add(i);
  end;

  Caption := IntToStr(_List1.List[0].Field) + IntToStr(_List2.List[0]);

  _List1.Free;
  _List2.Free;
end;

在调试过程中如何查看tList<Integer>?

How can I look into tList<Integer> during the debugging?

推荐答案

通常,应该可以在List属性上看到包含数组的列表.内部只有一个Pointer类型的字段,与10.3之前的TArray<T>类型不同.

Usually it should be possible to see the lists contained array over the List property. Internally there is only a field of type Pointer unlike before 10.3 when it was of type TArray<T>.

当我将断点放入分配给Caption的行中并将这两个条目放入我的手表时,这就是我看到的:

This is what I see when I put a breakpoint into the line where it assigns to Caption and put those two entries into my watches:

更新:看起来链接器负责您在此处遇到的问题.当您取消选中手表中的允许副作用和函数调用"选项时

Update: It looks like the Linker is responsible for the issue you are experiencing here. When you uncheck the option to "allow side effects and function calls" in the watch

监视窗口将显示以下内容:

the watch window will show this:

在使用仅在单元的实现部分中指定的泛型时,我已经看到了此行为(FWIW,当我第一次尝试复制时,我没有将您发布的代码放入VCL项目中,而是放入控制台中) dpr,而该对象没有实现部分,因此我没有看到此行为.)

I have seen this behavior before when using generics that are only specified in the implementation part of the unit (FWIW when I tried to repro this the first time I did not put the code you posted into a VCL project but into a console dpr and that one does not have an implementation part so I did not see this behavior).

要强制链接器不要删除符号或调试器使其实际看到它(因为即使我禁用内联以强制GetList方法停留在监视窗口中,也会告诉我它已被删除),您可以简单地放置一些虚拟类型输入到此单元或任何其他单元的interface部分.

To force the linker to not to remove the symbol or the debugger to actually see it (because even if I disable inlining to force the GetList method to stay the watch window will tell me that it got removed) you can simply put some dummy type into the interface part of this or any other unit.

type TDummy = TList<Integer>;

这将使调试器看到符号并在监视窗口中看到值.

This will cause the debugger to see the symbol and see the values in the watches window.

这篇关于如何在Delphi调试期间查看通用tList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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