Recent

Author Topic: Beginner can't debug a string grid  (Read 443 times)

mawg

  • Newbie
  • Posts: 3
Beginner can't debug a string grid
« on: September 16, 2024, 10:53:24 pm »
I just switched from Delphi to Lazarus.

I hi t a breakpoint, and examine my stringgrid, but can't see properties like RowCount, Rows or Cells. I could post what the debugger shows me, but it's 850+ lines long.

It starts

Quote
TStringGrid( {TCustomStringGrid}
  private
  FModified: False;

So I am looking at a stringgrid. What's the "one weird trick" to let me examine the most common attributes?

Apologies for asking something so basic. I really do want to switch to Lazarus

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10310
  • Debugger - SynEdit - and more
    • wiki
Re: Beginner can't debug a string grid
« Reply #1 on: September 17, 2024, 09:09:23 am »
You need to know the fields that hold the data.

Unfortunately properties (with getter function) are currently not available for the debugger. (gdb didn't know them, and the compiler hasn't yet been updated).

In some cases you may be able to call the function directly (in the "watches" window).
You need to enable function calling under menu: Tools > Options > Debugger
And also in the properties of the watch.
And then you can enter something like "MyGrid.GetWhateverNameTheFunctionHas()".

In current Lazarus 3.4 it may not work always (because again the info is not always included by the compiler), with 3.99 more of the functions can be called.



Mind that calling function can modify the state of your app.

That is also true for inspecting properties in Delphi.

If you call a function from the debugger (and again that includes inspecting properties in Delphi) then the function is executed. If that function has side efferts (such as changing any field/var) then that change persist, and the app may behave different than it would have otherwise. (And again: Same in Delphi).

mawg

  • Newbie
  • Posts: 3
Re: Beginner can't debug a string grid
« Reply #2 on: September 23, 2024, 01:16:26 pm »
Apologies that it has taken me so long to reply. And thank you very much taking the time to try to help.

I couldn't add a watch, because

Quote
PassagesStringGrid @$0000000001407310 = TStringGrid(... [snip]
PassagesStringGrid.RowCount = Member not found: RowCount

My initial reaction was to punch my laptop screen and go back to Delphi. I just can't understand why such a widely revered piece of software as Lazarus can't do something so basic. [/rant]

However, if I fancy I challenge, I can latch on to what you said

Quote
properties (with getter function) are currently not available for the debugger

1) is there any plan to address this? And, 2) do you think that I could subclass the grid - and other controls - and add getters/setters? Of course, then I would have to create my entire GUI dynamically, and would not have access to the Object Inspector at design time, which is a major pain.

I normally use Delphi, but am coding an app to help with designing Interactive Fiction. I thought it would be in the spirit of Open Source if I used Lazarus. Now I am thinking that I could be imposing problems on anyone who forks the project and should probably stick with Delphi Community edition. What do you think?

No anger here, but the debugger is my best friend. Thanks again for your reply

Zvoni

  • Hero Member
  • *****
  • Posts: 2692
Re: Beginner can't debug a string grid
« Reply #3 on: September 23, 2024, 01:34:46 pm »
The way i do it (exactly because of the reasons mentioned):
I introduce a (local) variable, which is only visible in Debug-Mode
Code: Pascal  [Select][+][-]
  1. Var
  2.   {$IFDEF Debug}rc:Longint;{$IFEND}
  3. ........
  4.   {$IFDEF Debug}rc:=MyStringGrid.RowCount;{$IFEND}  //And i examine the variable RC in the Debug-Window

Yes, some might find that annoying, but... *shrug*
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10310
  • Debugger - SynEdit - and more
    • wiki
Re: Beginner can't debug a string grid
« Reply #4 on: September 23, 2024, 01:47:40 pm »
Quote
1) is there any plan to address this?
Kind of, yes.

It involves a lot of ground work. For something to work in the debugger it is necessary that the compiler provides debug info, which means debug info must support it.... https://dwarfstd.org/issues/240507.1.html
Then when debug info supports it (or earlier if enough info is avail) it must be added to the compiler. Which means the very earliest is FPC 3.4, if it is avail by then, and if the FPC team can fit it in.
And then it can be added to the debugger.



For now, this works:
Code: Pascal  [Select][+][-]
  1. Property Something: integer read FSomeThing;
Because the compiler adds "Something" as a field to debug info (i.e. pretends its a field not a property).

But this does not work
Code: Pascal  [Select][+][-]
  1. Property Something: integer read GetSomeThing;


If in the above "GetSomething is virtual then you can (should be able to) watch (in 3.4), at least on Windows, but afaik Linux too.
Code: Pascal  [Select][+][-]
  1. StringGrid1.GetRowCount()
(If you enabled "function calling" in the global settings, and in the watch properties).


In Lazarus 3.99 then (as far as I tested) this works for non-virtual methods too.

There may more issues if there are nested classes...

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10310
  • Debugger - SynEdit - and more
    • wiki
Re: Beginner can't debug a string grid
« Reply #5 on: September 23, 2024, 01:49:58 pm »
For your case, you can also watch:
Code: Text  [Select][+][-]
  1. stringgrid1.FRows.Count

Just navigate to the implementation of a getter function (alt cursor up), and check where the data comes from.

 

TinyPortal © 2005-2018