How can I show the contents of a TStringList in the debugger?
Asked Answered
B

5

9

I want to display the entire content of a TStringList while debugging the application. Instead I just get pointers. The Flist is showing only the address.

Beffrey answered 15/8, 2011 at 16:21 Comment(4)
In debug mode, it is possible to evaluate an expression (FList.Text) to see the whole content.Pinstripe
But IIRC (can't check right now) only if you enable functions calls for types during debugging.Mutate
@Rudy: This is only true for watches. In the "Evaluate and modify" window function (and procedure e.g setter) calls are always possible.Kannry
I generally have lots of watches and seldom use the "evaluate and modify" dialog. I like my values to be visible all the time.Mutate
F
2

I use the visualizers now that I have D2010. I used to use a function I called CArray that would return an array of strings. If I added CArray(MyStringList) to the watch window, I would be able to examine the contents of the string list. I used to be employed to write VB6 code and I sort of liked the various 'C' functions for converting to a useful type. CArray for stringlists and CArray for ClientDataset fields were mostly useful for debugging.

  function  CArray(List: TStrings): TStrArray; Overload;
  var i,
      iCount: Integer;
  begin
    iCount := List.Count;
    SetLength(Result, iCount);
    for i := 0 to Pred(iCount) do Result[i] := List[i];
  end;
Foret answered 15/8, 2011 at 20:48 Comment(1)
The new visualizers feature is nice (even nicer is that you can write your own custom visualizers!). The default TStrings visualizer that ships with the IDE does have some size limitations on the TStrings content, though.Skedaddle
D
7

If you are using Delphi 2010 or later, the debugger allows for this using debug visualizers.

For older versions, you can dump the contents of the Text property in the Watch window or using OutputDebugString, but that's difficult to read. You could set up watches for each element of the list, but that's only practical for very short lists.

I would probably use an external logging app like CodeSite or SmartInspect that let you dump the contents of a TStringList in a single call.

Dutchman answered 15/8, 2011 at 17:1 Comment(0)
N
5

Inspect the Text property. It's the concatenated version of the stringlist.

Nowhither answered 15/8, 2011 at 17:2 Comment(0)
R
3

Since i´m using BDS MMVI, i´m using an "ultra clever smart" method for that kind issue, i use it for large xml documents. I start context file editor (very capable free text editor writen in delphi by the way). On the debugger window a just do a FList.SaveToFile('contents.txt'), since context can monitor file modifications i can see whats happening in my xml files.

Sorry for the "clever" joke but it does work for me.

Peace

Reportage answered 16/8, 2011 at 11:38 Comment(1)
+1 You answer first :) I use ConTEXT too because it free and friendly, but file can be opened even in Delphi IDE.Echo
F
2

I use the visualizers now that I have D2010. I used to use a function I called CArray that would return an array of strings. If I added CArray(MyStringList) to the watch window, I would be able to examine the contents of the string list. I used to be employed to write VB6 code and I sort of liked the various 'C' functions for converting to a useful type. CArray for stringlists and CArray for ClientDataset fields were mostly useful for debugging.

  function  CArray(List: TStrings): TStrArray; Overload;
  var i,
      iCount: Integer;
  begin
    iCount := List.Count;
    SetLength(Result, iCount);
    for i := 0 to Pred(iCount) do Result[i] := List[i];
  end;
Foret answered 15/8, 2011 at 20:48 Comment(1)
The new visualizers feature is nice (even nicer is that you can write your own custom visualizers!). The default TStrings visualizer that ships with the IDE does have some size limitations on the TStrings content, though.Skedaddle
E
2

My two cents:

You can evaluate expression list_instance_variable.SaveToFile('temp_file_name.txt') and then examine content of the file in any editor.

To do that you must use this function anywhere in code and turn off optimization (at least in Delphi 7), otherwise object code of SaveToFile would be removed by the linker.

Echo answered 16/8, 2011 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.