Recent

Author Topic: how can i evaluate a TStringGrid in debug ?  (Read 707 times)

Nono Reading Activity

  • New Member
  • *
  • Posts: 11
how can i evaluate a TStringGrid in debug ?
« on: September 02, 2023, 06:34:45 pm »
Greetings,
i can't understand how to use the debug/evaluate with some objet.
In debug, if i want to check tstringgrid.rowcount or tstringgrid.cells[a,b] in a TStringGrid, it show me "member not found"
what am i doing wrong ?
thanks in advance.

Handoko

  • Hero Member
  • *****
  • Posts: 5060
  • My goal: build my own game engine using Lazarus
Re: how can i evaluate a TStringGrid in debug ?
« Reply #1 on: September 02, 2023, 07:31:09 pm »
Sorry for not answering your question.

I don't use that debug tool often. Instead I usually use:

Code: Pascal  [Select][+][-]
  1.   Form1.Caption := StringGrid1.Cells[a, b];

rvk

  • Hero Member
  • *****
  • Posts: 5651
Re: how can i evaluate a TStringGrid in debug ?
« Reply #2 on: September 02, 2023, 07:37:58 pm »
The debugger is not as perfect as the one in Delphi.
It can't evaluate property getters yet.
And TStringGrid.RowCount is a property with a getter function.
Code: Pascal  [Select][+][-]
  1.     property RowCount: Integer read GetRowCount write SetRowCount default 5;

You can get the value by accessing the correct field directly (normally the Fxxx variant).
For TStringGrid you can put this in a watch (or Ctrl+F7): StringGrid1.FRows.Count.

FRows is the direct variable for the rows and Count is a value of FRows.
And Count for FRows is not a getter but a direct read for Count in the TList FRows.
(otherwise you would have needed to do StringGrid1.FRows.FCount which also works)
« Last Edit: September 02, 2023, 07:40:10 pm by rvk »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9370
  • Debugger - SynEdit - and more
    • wiki
Re: how can i evaluate a TStringGrid in debug ?
« Reply #3 on: September 02, 2023, 08:03:53 pm »
Lazarus 3.0

For a single cell, enter as watch:
Code: Text  [Select][+][-]
  1. PCellProps((TFpList((StringGrid1.FGrid.FCellArr.FCols.FList)^[1]).FList)^[1])^

Modify either of the "1" to see other chells.




In fact, you can watch
Code: Text  [Select][+][-]
  1. StringGrid1.GetCells(1,1)
if you enable function calls (Tools > Options > Debugger) and then again in the watch properties.
https://wiki.freepascal.org/FpDebug-Watches-FunctionEval

Mind that only works, because StringGrid1.GetCells is virtual/overridden.

Since it involves strings, it needs DWARF-3 (project settings).


For non virtual methods there is a bug in FPC.
« Last Edit: September 02, 2023, 08:08:49 pm by Martin_fr »

rvk

  • Hero Member
  • *****
  • Posts: 5651
Re: how can i evaluate a TStringGrid in debug ?
« Reply #4 on: September 02, 2023, 08:11:16 pm »
Lazarus 3.0

For a single cell, enter as watch:
Code: Text  [Select][+][-]
  1. PCellProps((TFpList((StringGrid1.FGrid.FCellArr.FCols.FList)^[1]).FList)^[1])^

Modify either of the "1" to see other chells.
Hahaha, to make it easy  :D

Hopefully FpDebug will get the option to view properties (with or without getters) in the future, like Delphi  ;)


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9370
  • Debugger - SynEdit - and more
    • wiki
Re: how can i evaluate a TStringGrid in debug ?
« Reply #5 on: September 02, 2023, 08:13:15 pm »
Hopefully FpDebug will get the option to view properties (with or without getters) in the future, like Delphi  ;)

That depends on if the FPC team is going to add this to the debug info.

rvk

  • Hero Member
  • *****
  • Posts: 5651
Re: how can i evaluate a TStringGrid in debug ?
« Reply #6 on: September 02, 2023, 08:25:33 pm »
Hopefully FpDebug will get the option to view properties (with or without getters) in the future, like Delphi  ;)
That depends on if the FPC team is going to add this to the debug info.
Might not be "if" but "when"  ;)
I thought work on that has started.
(At least that's what you typed two years ago  :D )

https://wiki.freepascal.org/FpDebug#Properties
Quote
FPC needs a way to actually add info about the "properties" to the debug info. (as of end 2021: work has begun...)

But FpDebug already has come a long way.

I did find that my trunk install still defaulted to gdb.
I wonder if, with gdb now crashing in Lazarus with DWARF 3, and DWARF 3 being the default for AMD64, FpDebug should be default?

(but maybe that's offtopic for this thread)


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9370
  • Debugger - SynEdit - and more
    • wiki
Re: how can i evaluate a TStringGrid in debug ?
« Reply #7 on: September 02, 2023, 09:04:29 pm »
Hopefully FpDebug will get the option to view properties (with or without getters) in the future, like Delphi  ;)
That depends on if the FPC team is going to add this to the debug info.
Might not be "if" but "when"  ;)
I thought work on that has started.
(At least that's what you typed two years ago  :D )

https://wiki.freepascal.org/FpDebug#Properties
Quote
FPC needs a way to actually add info about the "properties" to the debug info. (as of end 2021: work has begun...)
Well, yes... And nothing since.



Quote
I did find that my trunk install still defaulted to gdb.
It should have asked at startup. But asked only once (as part of the --setup dialog).

Other than that once off question, a new install honours old config. If there is no old config, then it should setup fpdebug as default.



rvk

  • Hero Member
  • *****
  • Posts: 5651
Re: how can i evaluate a TStringGrid in debug ?
« Reply #8 on: September 02, 2023, 09:23:32 pm »
Quote
I did find that my trunk install still defaulted to gdb.
It should have asked at startup. But asked only once (as part of the --setup dialog).

Other than that once off question, a new install honours old config. If there is no old config, then it should setup fpdebug as default.
Ha, yes. I see now. I probably had a setting from earlier today with the 2.2.4 install.

The StringGrid1.GetCells(1,1) works perfect too  8)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9370
  • Debugger - SynEdit - and more
    • wiki
Re: how can i evaluate a TStringGrid in debug ?
« Reply #9 on: September 03, 2023, 06:51:58 pm »
Lazarus 3.0

For a single cell, enter as watch:
Code: Text  [Select][+][-]
  1. PCellProps((TFpList((StringGrid1.FGrid.FCellArr.FCols.FList)^[1]).FList)^[1])^

Modify either of the "1" to see other chells.
Hahaha, to make it easy  :D

I actually wanted to go a step further than the above, but it turned out 3.0RC1 has a bug...

Now, the bug is fixed in the branch, and 3.0RC2 will be able to do the below:
(mind the .. ranges)

Code: Text  [Select][+][-]
  1. PCellProps((TFpList((StringGrid1.FGrid.FCellArr.FCols.FList)^[0..6]).FList)^[0..5])^.Text

This returns an: Array[column] of Array[row] of pchar.
- 6 columns
- 5 rows in each column

The watches window, allows to browse them, as shown in the image.

Empty cells, return an error (for their array entry), because the grid has a nil value in the pointer to their date (and nil dereference is an error).

Data used:
Code: Pascal  [Select][+][-]
  1. StringGrid1.Cells[1,1]:='Column:1 Row: 1';
  2. StringGrid1.Cells[1,2]:='Column:1 Row: 2';
  3. StringGrid1.Cells[2,1]:='Column:2 Row: 1';


Of course you can replace the "5" in "0..5" with "StringGrid1.FRows.FCount". And do similar for the column count.
But mind, that this means a grid with 1000 rows will have the debugger evaluate them all.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9370
  • Debugger - SynEdit - and more
    • wiki

 

TinyPortal © 2005-2018