How to look into generic tList during Delphi debugging

北城余情 提交于 2020-03-16 05:54:06

问题


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

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.

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;

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


回答1:


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>.

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:

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).

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.



来源:https://stackoverflow.com/questions/56560857/how-to-look-into-generic-tlist-during-delphi-debugging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!