Ladění ve Freepascalu - náhled do objektu

https://forum.lazarus.freepascal.org/index.php/topic,58575.0.html

procedure TMyApplication.prepareParms(var Pars: TStringList);
var i: integer;
  sFN: string;
  strA: Array of String;
begin
  Pars.NameValueSeparator := '=';
  sFN := '';
  for i := 1 to paramCount do
      begin
        strA := paramStr(i).split('=');
        if strA[0][1]='-' then
          strA[0]:=copy(strA[0],2,length(strA[0]));
        Pars.Add(strA[0].ToLower+'='+AnsiDequotedStr(strA[1],'"'));
      end;
  if Pars.count>0 then
    begin
      for i := 0 to Pars.count-1 do
          begin
            if (Pars.Names[i]='configfile') OR (Pars.Names[i]='config-file') OR (Pars.Names[i]='config') then
              begin
                sFN := AnsiDequotedStr(Pars.ValueFromIndex[i],'"');
                break;
              end;
          end;
      if not fileexists(sFN) then
         writeln('File not found '+sFN)
      else
        begin
          writeln('Reading config file '+sFN);
          Pars.Clear;
          Pars.LoadFromFile(sFN);
          for i := 0 to Pars.Count-1 do
              begin
                if Pars.ValueFromIndex[i][1]='-' then
                  Pars.ValueFromIndex[i]:=copy(Pars.ValueFromIndex[i],2,length(Pars.ValueFromIndex[i]));
                Pars.ValueFromIndex[i] := AnsiDequotedStr(Pars.Values[Pars.ValueFromIndex[i]],'"');
              end;

        end;
    end;
end;


Debug Evaluate:

PStringItemList(Pars.FList)^[0]

 

The debugger (any debugger) is limited to whatever info it gets from the compiler. It's called debug-info (..g., "DWARF").  

Další tipy!

- assuming "var L: TStringList;"

- you use FpDebug / LazDebuggerFp
- Your RTL is build with debug-info / and RTL debug-info is set to "DWARF" (any of the dwarf settings / for FpDebug your can go with DWARF-3)

Code: Text  [Select][+]
  1. (L.FList)^[0]
Code: Text  [Select][+]
  1. (TStringList(L).FList)^[0]

You can use the "Debug-inspector" (menu: Run > Inspect).
There you can inspect the variable "L", and double-click the "FList" field, then again double click the entry "L.FList" to deref the pointer.
After that you need to edit the expression yourself, and add the "[0]" (or whatever index you want).
Once you got the entry, you can press the "Add watch" button. (you can then edit the index, and add more watches)

Or you can add the following watch (may depend on your fpc version)
Code: Text  [Select][+]
  1. (TStringList(L).FList)^
And set a "repeat count" in the watch properties. (Without repeat count you may get a hell of a lot of entries / more than the list actually has).



If your RTL does not have debug info you can try
Code: Text  [Select][+]
  1. ^AnsiString(L.FList)[i*2]
where i is the index.

Tip pro Lazarus 3.0

Rozsah pro prohlížení více záznamů e.g. [0..3] místo zadávání po jednom indexu.

https://forum.lazarus.freepascal.org/index.php/topic,63869.0.html

Komentáře

Oblíbené příspěvky