To DebugLn or not to DebugLn? lazarus / 12-Debugger ---------------------------------------------------------------------- WooBean · 2023-07-06 13:48 Does anybody know how to use DebugLn to answer more detailed questions? 1. Is this somewhere documented? If yes, where  to find? 2. What a user should do in Lazarus IDE config to observe an output of DebugLn? 3. Can it be a file or "Debug Output" window docked into (or detached of) the IDE? Some time ago I asked forum about Event Logging. Hoped  that this is a way to make debugging easier. Not especially, I think now. ---------------------------------------------------------------------- Martin_fr · 2023-07-06 14:08 1) There is info on the wiki under LazLogger. (search for LazLogger should bring up the page) That isn't IDE specific, that is general info 2) - run from a console (on Windows, compile IDE with -WC) - or lazarus.exe --debug-log=file   and then as needed --debug-enable (or install ide-lazlogger package, wich can toggle those at runtime) 3) a file, see above ------------------ Quote Event Logging.scrap the above (Except first point) Up till this line your question was about debugln. debugln in the IDE has nothing todo with debugging your app. It will print out internals of the IDE, if you debug the IDE itself. Also debugln is entirely independent of the debugger => it always (even if you run an app outside the IDE) prints to console, or to a file (which by default is specified by --debug-log= / but can be configured / see wiki ) On Windows there is a WinAPI call to write to a debugserver => and that can be displayed in the event log -- but will be mixed with all the rest. (I need to google to find the details on calling this in the debugged app => might leave the google to you). On Windows, you can compile your app with -WC (or disable GUI app) => and then if you debugln in your app, you have a console (that will work in the debugger or outside of it) On Linux it goes always to the console or the debug window for the console output. ---------------------------------------------------------------------- Martin_fr · 2023-07-06 14:10 ok, on 2nd read I see what you mean / just misleading as debugln has so many purposes. Just disable "gui app" in the project settings => or compile with -WC Then you still can use forms and all, but will have a console too. And then all your debugln goes to the console. ------------- the wiki should have details how to set it to a logfile instead. ---------------------------------------------------------------------- WooBean · 2023-07-06 14:30 Referring to 2nd post - Quote from: Martin_fr on July 06, 2023, 04:10:55 pm.. Just disable "gui app" in the project settings => or compile with -WC Then you still can use forms and all, but will have a console too. And then all your debugln goes to the console. ------------- the wiki should have details how to set it to a logfile instead. For 'normal' GUI application (on Windows) this way worked and still works (3.0RC1 I mean) but not for Lazarus IDE itself, shade. ---------------------------------------------------------------------- Martin_fr · 2023-07-06 14:47 Quote from: WooBean on July 06, 2023, 04:30:58 pmFor 'normal' GUI application (on Windows) this way worked and still works (3.0RC1 I mean) but not for Lazarus IDE itself, shade. For the IDE itself you have to put -WC into "Configure build lazarus" ---------------------------------------------------------------------- WooBean · 2023-07-06 14:50 I have wanted exactly this! Many thanks! ---------------------------------------------------------------------- CM630 · 2026-08-12 13:03 I need to debug how an LPK behaves in the design mode of Lazarus. Can I use debugmode or something else? I tried to run lazarus from the console and use writeln, but it crashes, says “..file not open”.  :'( ---------------------------------------------------------------------- Thausand · 2026-08-12 13:21 Quote from: CM630 on August 12, 2026, 03:03:53 pmI tried to run lazarus from the console and use writeln, but it crashes, says “..file not open”.  :'( That strange. Is work for me but is linux. You uses windows ? Then may be is setting project option / compiler options / config and target / win32 gui application (is default on and is cause this error). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  writeln('form.create');end; end.  Code: [Select]$ ./test form.create PS: debugln can use when use debug server that is catch debugln. This independent freepascal/lazarus but can use fpc/laz debugserver. ---------------------------------------------------------------------- CM630 · 2026-08-12 15:32 Quote from: Thausand on August 12, 2026, 03:21:20 pm... Then may be is setting project option / compiler options / config and target / win32 gui application (is default on and is cause this error). ... I do not want to debug a project, but an LPK (visual control) installed in Lazarus. So I need the behaviour before pressing F9. ---------------------------------------------------------------------- Thausand · 2026-08-12 16:16 Quote from: CM630 on August 12, 2026, 05:32:50 pmI do not want to debug a project, but an LPK (visual control) installed in Lazarus. So I need the behaviour before pressing F9. Ok, then when have terminal/commandline and have run Lazarus. Martin_fr have write instruct how do this when have Windows. ---------------------------------------------------------------------- Martin_fr · 2026-08-12 19:01 Do use "writeln" or "debugln" in code that runs as part of the IDE (your own component in the Designer of the IDE)... If you are on Windows compile the IDE with -WC --------- Using the debugger: - Enable debug info in your packages options - Open ide/lazarus.lpi and run it in the debugger. A 2nd IDE will start, and you will debug that entire 2nd IDE, including your component as it is called by that IDE in the designer.