Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to look into generic tList during Delphi debugging

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.

enter image description here

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?

like image 253
SHIN JaeGuk Avatar asked Jan 27 '23 04:01

SHIN JaeGuk


1 Answers

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:

enter image description here

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

enter image description here

the watch window will show this:

enter image description here

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.

like image 76
Stefan Glienke Avatar answered Jan 29 '23 20:01

Stefan Glienke