Is there a Debugging Window on Lazarus? lazarus / 12-Debugger ---------------------------------------------------------------------- Edson · 2013-10-27 22:29 In console mode, we can use a simple WriteLn() for output some value to screen. But in Windows Apps, it doesn't work. I am looking for some easy way for show strings on Windows Apps (No need for to use a file or to config an environment variable, or to use command line, like DebugLn need). ---------------------------------------------------------------------- Martin_fr · 2013-10-27 23:01 Compile the app as console app. There is a checkbox "win32 gui application"  (in "Project options"  exact place depends on which version you have, in 1.3 it is "Config and Target") Uncheck it, and you get a console window. Or write to StdErr, and watch the debug event log. ---------------------------------------------------------------------- Edson · 2013-10-27 23:50 Thanks Martin, I can see now, the output on the console window, when I use writeln(). But it's annoying, when I get an error on execution time when I check again the "win32 gui application".  I must comment all the writeln() or use and conditional directive, for all the writeln(). ---------------------------------------------------------------------- Martin_fr · 2013-10-28 01:15 use debugln instead. It checks for the availability of STDOUT. And you can change the uses clause LazLoggerDummy : all debugln are just empty methods, so your code will not do anything (well fpc may leave a few calls to an empty method) LazLogger : fully functional. Also adds check for commandline options --debug-log and --debug-enable (can be configured LazLoggerBase : inactive. LCLProc : nor sure, same as LazLogger or LazLoggerBase --- LazLoggerBase  is supposed to be used in most units.  Then as soon as you add LazLogger to ONE unit all LazLoggerBase become active. ---------------------------------------------------------------------- Edson · 2013-10-28 03:51 It seems that "LazLogger" is very complete. But, does debugLn() have a window for show the output? ---------------------------------------------------------------------- Leledumbo · 2013-10-28 09:07 QuoteBut, does debugLn() have a window for show the output?AFAIK, debug server (in tools menu) will show the output of debugln. ---------------------------------------------------------------------- Martin_fr · 2013-10-28 11:21 Not sure which package debugserver is, it is not there by default. There actually is a special write to debugserver command, but I do not remember. Debugln writes to STDOUT (same as writeln). The difference isn that it does not crash, if there is no console. And it can be redirected to a logfile if wanted. Together with a "tail" application that can also be used. ---------------------------------------------------------------------- Leledumbo · 2013-10-28 15:39 QuoteNot sure which package debugserver is, it is not there by default.No package required, it's there: $LazarusDir()/tools/debugserver/debugserver$ExeExt() Strange, I remember never touch anything and it is there from the start. ---------------------------------------------------------------------- Martin_fr · 2013-10-28 15:50 See picture. Tools menu of a fresh install. No debugserver entry ---------------------------------------------------------------------- Edson · 2013-10-29 04:13 It's not in tool menú. It's an executable that must be in:  $LazarusDir()/tools/debugserver/ But in my Lazarus, it doesn´t exist. I had to compile the project that was in that place, for getting the executable. Once executed, the "debugserver.exe" work fine. It show the message of my app, if I use the unit "dbugintf" and call the function "SendDebug()". But it need, to have the debugserver.exe, always running. If I stop the process, it give me an Error on execution time. (It's the same of using WriteLn on no "win32 gui application" mode). ---------------------------------------------------------------------- Leledumbo · 2013-10-29 06:11 OK maybe a long time ago I put it in my tools menu as custom tool, so I can call it conveniently. You can also use event log window, using TEventLog as debugging aid. ---------------------------------------------------------------------- Edson · 2013-10-29 19:02 I probed the TEventLog object, and it worked, but honestly it's a complicated way for view debugging message. It has a lot of unuseful information. Until now I can see that "There is not a simple way for viewing message on a debugging window." I was expecting to have some like: uses ..., debugWin; ... debug('hello'); ... And no more. I think it's necessary to have at least a simple Debug Windows on Lazarus, considering that we don't have a good debugger. ---------------------------------------------------------------------- Martin_fr · 2013-10-29 19:19 Personally I use debugln. If you define buildmodes, the changing between with and without console window is just making a selection in a dropdown on the main toolbar (no dialog, immediately reachable) debugln does not fail if there is no console, And it can be eliminated (by substituting the unit) for release builds. --- The biggest shortcoming of the debugger imho is the lack of function calling (and with that the ability to see properties). It has rarely ever affected me. Normally I know the underlying field, and can watch this. Also make sure to use DWARF, so   property FOO: Integer read FFOO; will work (no function, direct to field) ---------------------------------------------------------------------- Edson · 2013-10-30 00:11 Thanks Martin, it's a good option, to use debugLn with "Build Modes".  I think I can use that way too. However It's necessary to configure for each project, a little extra job. Probably later I will try to make my own debug Window. I don't hate black console window, but i think it doesn't fit at the Lazarus standar. I think Lazarus is a great IDE, but has so many options that anyone can confuse at the first time. Probably could have a some different default configuration. Moreover, I see a lack of documentation on Lazarus or if we have, it's not correctly organized. ---------------------------------------------------------------------- GeertVc · 2017-08-13 07:53 Quote from: Martin_fr on October 29, 2013, 08:19:29 pmPersonally I use debugln. If you define buildmodes, the changing between with and without console window is just making a selection in a dropdown on the main toolbar (no dialog, immediately reachable) debugln does not fail if there is no console, And it can be eliminated (by substituting the unit) for release builds. I know this is an old thread, but I just stepped in into Lazarus and stumbled upon the same.  Build mode is a nice alternative, as is the debugserver alternative.  However, it's anyhow a pitty that WriteLn() doesn't work with Windows GUI's or that DebugLn() is not rerouted to the default available Messages window... ---------------------------------------------------------------------- ASerge · 2017-08-13 09:14 View/Debug Windows/Event Log (Ctrl+Alt+V) 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 uses Windows; procedure DebugLn(const Text: string); overload;var  Data: UnicodeString;begin  Data := UTF8Decode(Text);  OutputDebugStringW(PWideChar(Data));end; procedure DebugLn(const FmtText: string; const Params: array of const); overload;begin  DebugLn(Format(FmtText, Params));end; procedure TForm1.FormCreate(Sender: TObject);begin  DebugLn('One');  DebugLn('DebugLn addr: %p', [@DebugLn]);end; ---------------------------------------------------------------------- GeertVc · 2017-08-13 09:57 Well, what can I say.  Newbie, I am...  PS: I had to include sysutils too to get it working (provides "Format"). ---------------------------------------------------------------------- avra · 2017-08-13 10:18 Quote from: GeertVc on August 13, 2017, 09:53:28 amHowever, it's anyhow a pitty that WriteLn() doesn't work with Windows GUI'sYou might want to take a look at MultiLog: http://wiki.lazarus.freepascal.org/MultiLog ---------------------------------------------------------------------- grandehombre · 2020-09-01 22:18 Unfortunately, that project (MultiLog) has a reference to an OutputChannel unit that does not exist  :-( ---------------------------------------------------------------------- avra · 2020-09-01 22:58 Quote from: grandehombre on September 02, 2020, 12:18:03 amUnfortunately, that project (MultiLog) has a reference to an OutputChannel unit that does not exist  :-(OPM version does not have that problem.