Recent

Author Topic: Strange IDE behavior at code location  (Read 1614 times)

davec

  • Newbie
  • Posts: 2
Strange IDE behavior at code location
« on: May 11, 2024, 07:49:25 am »
Hello everyone,

I am new to Lazarus and Delphi and have a strange behavior in my project.

It is about the following place in the code (mainmenu.pas):
Code: Pascal  [Select][+][-]
  1. frmDatenEinlesen.DataExchange := Self;
  2.  

After I execute the program in the IDE and confirm the "Insert new Data" button in the "mainmenu.lfm", the program exits (without a debug message) and I end up in the source code view. However, as soon as I compile the program and execute the EXE file, everything works perfectly.

What is the reason for this? Do you have a solution for this?

I have attached the project.
The sqlite3.dll must be inserted in the program directory for correct program execution (unfortunately only ZIPS up to max. 500 KB are allowed here, otherwise I would have already inserted it): https://www.sqlite.org/download.html (sqlite-dll-win-x64-3450300.zip)

Many thanks for your help!

Best regards
Dave


Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12202
  • Debugger - SynEdit - and more
    • wiki
Re: Strange IDE behavior at code location
« Reply #1 on: May 12, 2024, 10:42:14 am »
I am not currently going to run it on my machine, but a few ideas....

Quote
the program exits (without a debug message) and I end up in the source code view.
Just to double check
- the IDE title no longer says "debugging"?
- the blue dots in the editor-gutter disappear?


Menu: View > debug windows > event log
When the app ends, does it say anything in the event log window?


Menu: Tools > Option / Debugger > Backend
Have you tried FpDebug and/or GDB based backends?


Have you set a breakpoint on that line, and then stepped in with F7?



Have you compiled both (the "debugging" and "run outside the IDE") with the same settings?
« Last Edit: May 12, 2024, 10:56:32 am by Martin_fr »

cdbc

  • Hero Member
  • *****
  • Posts: 2685
    • http://www.cdbc.dk
Re: Strange IDE behavior at code location
« Reply #2 on: May 12, 2024, 11:20:48 am »
Hi
OK, so I've got your program running in my laz 2.2.6, debugging, doesn't matter that it's on linux  :D
Right so what exactly is your problem?!?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

davec

  • Newbie
  • Posts: 2
Re: Strange IDE behavior at code location
« Reply #3 on: May 12, 2024, 11:55:21 am »
@Martin_fr

Thank you!

1. the IDE title says still "debugging..."
2. the blue dots in the editor-gutter are already there.
3. the event log is empty

4. i changed the debugger backend from FpDebug to GDB.

Now it works flawlessly! What could be the reason? Why does it not work with FpDebug?

@cdbc
In FpDebug, the application exits in the middle of execution. I am using Windows 10 with Lazarus 3.2.
I have attached a screenshot.

@all
I have another problem

Code: Pascal  [Select][+][-]
  1. procedure TFormDatenEinlesen.AnalyzeDataSorting(const Data: TStringList) string;
  2. var
  3.   I: Integer;
  4.   Ascending, Descending, PartiallySorted: Boolean;
  5. begin
  6.   if Data.Count = 0 then
  7.     Exit('No data available for analysis.');
  8.  
  9.   Ascending := True;
  10.   Descending := True;
  11.   PartiallySorted := False;
  12.  
  13.   // Check for complete sorting
  14.   for I := 0 to Data.Count - 2 do
  15.   begin
  16.     if Data[I] > Data[I+1] then
  17.       Ascending := False;
  18.     if Data[I] < Data[I+1] then
  19.       Descending := False;
  20.   end;
  21.  
  22.   if Ascending then
  23.     Exit('Already sorted: ascending');
  24.   if Descending then
  25.     Exit('Already sorted: descending');
  26.  
  27.    // Check for partial sorting
  28.   for I := 0 to Data.Count - 3 do // Attention: Change to Data.Count - 3 to avoid index errors
  29.    begin
  30.      if (Data[I] <= Data[I+1]) and (Data[I+1] <= Data[I+2]) then
  31.        PartiallySorted := True;
  32.      else if (Data[I] >= Data[I+1]) and (Data[I+1] >= Data[I+2]) then
  33.        PartiallySorted := True;
  34.    end;
  35.  
  36.   if PartiallySorted then
  37.     Exit('Partially sorted');
  38.  
  39.   Result := 'Randomly distributed';
  40. end;    


Code: Pascal  [Select][+][-]
  1. unit FormDatenEinlesen;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, DB,
  7.   SQLite3Conn, SQLDB, IDataExchange;
  8.  
  9. type
  10.   { TFormDatenEinlesen }
  11.   TFormDatenEinlesen = class(TForm)
  12.  ...
  13.   private
  14.  ...
  15.     function AnalyzeDataSorting(const Data: TStringList): string;    

Where did I make the mistake?

The debugger tells me:

Code: Pascal  [Select][+][-]
  1. formdateneinlesen.pas(110,74) Error: Syntax error, ";" expected but "STRING" found

on this line:

Code: Pascal  [Select][+][-]
  1. procedure TFormDatenEinlesen.AnalyzeDataSorting(const Data: TStringList) string;  

Thank you!

Regrads
Dave


 



« Last Edit: May 12, 2024, 12:49:07 pm by davec »

cdbc

  • Hero Member
  • *****
  • Posts: 2685
    • http://www.cdbc.dk
Re: Strange IDE behavior at code location
« Reply #4 on: May 12, 2024, 01:03:57 pm »
Hi
Code: Pascal  [Select][+][-]
  1. unit FormDatenEinlesen;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, DB,
  7.   SQLite3Conn, SQLDB, IDataExchange;
  8.  
  9. type
  10.   { TFormDatenEinlesen }
  11.   TFormDatenEinlesen = class(TForm)
  12.  ...
  13.   private
  14.  ...
  15.     function AnalyzeDataSorting(const Data: TStringList): string;
  16.     ////////////////////////////////////////////////////////////////////
  17.     procedure TFormDatenEinlesen.AnalyzeDataSorting(const Data: TStringList) string;
  18.     ?????????///////////////////////////////////////////////??????????<:>????  
Well Duh!!!
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12202
  • Debugger - SynEdit - and more
    • wiki
Re: Strange IDE behavior at code location
« Reply #5 on: May 12, 2024, 01:17:27 pm »
Ok, forgot to ask, what version of Lazarus do you use?  (I can infer from the dll link that you are on 64bit Windows)

1. the IDE title says still "debugging..."

So then it is still debugging. Just for some reason not telling you that/where/if it paused...

With the original issue (fpdebug)

1) Check the run/pause buttons in the main bar. Is the green run button enabled? Then the app is paused
2) Check menu View > debug windows > callstack
  It should show something, likely you are paused in some dll
  Normally in such cases the assemble window opens....

If it is paused still leaves the question why gdb does not enter pause.

Quote
4. i changed the debugger backend from FpDebug to GDB.

Now it works flawlessly! What could be the reason? Why does it not work with FpDebug?

Looking at your screenshot...

1) You have a breakpoint on the "unit" line
2) You are paused at the unit line.

Normally, that "unit" line does not produce code, and you can't pause there.

If (in case of normally) there is no code there, then
- FpDebug will ignore such a breakpoint
- GDB will break at the first line of code below that => that will be potentially 100 lines later, in the very first procedure of the unit.

And if it isn't "normally".... And I am not sure that applies here. I have seen similar but not exactly...
But you seem to be paused on that line, and that means it isn't "normally".
Sometimes FPC generates incorrect line info. (especially if you have optimization enabled, but sometimes even without that). In that case the "unit" line would most likely be attributed to the last line of code in some other unit (really complex underlaying issue).
So if it is not normally, have a look at the callstack, and the name of the procedure it says on the first line of the callstack




As for how to get it work => remove the breakpoint from that "unit MainMenu" line.
Check for other breakpoints in places that aren't inside a procedure.


440bx

  • Hero Member
  • *****
  • Posts: 6154
Re: Strange IDE behavior at code location
« Reply #6 on: May 12, 2024, 01:41:19 pm »
I must be missing something...

one of the code pieces shows an error about the compiler expecting a semicolon and finding "string" instead.

How can code that doesn't compile be debugged ???

something doesn't add up.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

cdbc

  • Hero Member
  • *****
  • Posts: 2685
    • http://www.cdbc.dk
Re: Strange IDE behavior at code location
« Reply #7 on: May 12, 2024, 01:54:44 pm »
Hi
@440bx: Look at my response to his error: I just put 2 of his listings into 1 and 'lo and behold' => one is a *function*, but becomes a *procedure* in the implementation...
Something is functioning at his end, because the code I've got running /from him/ doesn't have this function/procedure  %), methinks the problem lies higher & further away...  ::)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: Strange IDE behavior at code location
« Reply #8 on: May 12, 2024, 01:58:26 pm »
something doesn't add up.
Things usually adds up to 42 for me  :D
Today is tomorrow's yesterday.

 

TinyPortal © 2005-2018