[INFO] LazDebugUnit lazarus / 34-Windows ---------------------------------------------------------------------- JimD · 2018-09-03 03:44 LazDebugUnit Updated with v2.0 Methods and Examples View or download from: https://github.com/jasc2v8/LazUnits English only, Windows only, Unlicense (Public Domain) Overview DebugUnitMgr adds or removes a DebugForm to a Lazarus Project. The DebugForm consists of the units debugform.pas and debugform.lfm. Currently, debugging support for Free Pacal / Lasarus IDE has limited support on Windows. In lieu of a fully functional debugger, the DebugForm enables debugging with "old school" methods. Debug Example: 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 Debugln('Entering Function Add');Result:=Add(2,2);Debugln('Exit Function Add, check for exceptions, result should be 4, actual is: %n ', Result); Methods 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 procedure Debugln(Arg1: Variant);procedure Debugln(Arg1, Arg2: Variant);procedure Debugln(Arg1, Arg2, Arg3: Variant);procedure Debugln(Arg1, Arg2, Arg3, Arg4: Variant);procedure Debugln(Arg1, Arg2, Arg3, Arg4, Arg5: Variant);procedure Debugln(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6: Variant);procedure Debugln(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7: Variant);procedure Debugln(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8: Variant); procedure Debugln(Args: array of Variant); procedure Debugln(Fmt:string; Args: array of Const); Examples 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 Debugln('Unformatted output up to 8 Args of any Type:');Debugln('----- ---------------------------------------');Debugln(1,2,3,4,5,6,7,8);Deb ugln('binary=', %010);Debugln('boolean=', true);Debugln('decimal=', 10);Debugln('general=', 3.1415927);Debugln('hex=', $0010);Debugln('octal =', &0010);Debugln('scientific=', 1.9E6);Debugln('signed=', -100, ' or ', +100);Debugln('string=', 'the quick brown fox');Debugln('mixed bin=',%010,',bool=',true,',dec=',10,' ,gen=',3.1415927); Debugln(LE+'Unformatted output with Array of Varian t:');Debugln('----------------------------------------- ');Debugln(['decimal', -1,true,3.1415,4,5]);Debugln(['T1=', true,',T2=',false,',T3=',01.23]); Debugln(LE+'Formatted output with Array of Const:');Debugln('------------------------------------- ');Debugln('boolean    =%s or %s', [BoolToStr(true,false), BoolToStr(true,true)]);Debugln('currency   =%m', [1000000.]);Debugln('decimal    =%d', [-1]);Debugln('float      =%f', [3.1415927]);Debugln('general    =%g', [3.1415927]);Debugln('hex      =%x', [-1]);Debugln('number     =%n', [1000000.]);Debugln('scientific =%e', [1.0e3]);Debugln('string     =%s', ['the quick brown fox']);Debugln('unsigned   =%u', [-1]);Debugln('mixed cur  =%m, dec=%d',[1000000., 10]);Debugln('mixed float=%f, num=%n',[3.1415927, 1000000.]); ---------------------------------------------------------------------- JuhaManninen · 2018-09-03 04:47 LazUtils package has units LazLoggerBase and LazLogger. There is DebugLn() with a more flexible syntax, taking any number of variant parameters. ---------------------------------------------------------------------- JimD · 2018-09-03 14:05 JuhaManninen, Thank you for your excellent reply. Yes, I experimented with LazLogger.  It will send output to a file or the command window if I uncheck "Win32 GUI application" in the project options.  In contrast, LazDebugUnit sends output to a form in a separate window.   I just find this easier to work with for my small projects, and I can save the text from the memo on the form easier than from the command window.  The DebugUnitMgr is a convenience utility that will add or remove the DebugUnit from the project. I agree that the Debugln method in LazDebugUnit needs some work, and that is on my TODO list in the near future. I also experimented with a several others, which were great but are suited for more complex projects: http://lazarus-ccr.sourceforge.net/docs/fcl/eventlog/teventlog.html http://lazarus-ccr.sourceforge.net/docs/fcl/dbugintf/ http://wiki.lazarus.freepascal.org/MultiLog http://wiki.lazarus.freepascal.org/log4delphi ---------------------------------------------------------------------- Martin_fr · 2018-09-03 16:12 You can write your own subclass of lazlogger, just overriding 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     procedure DoDbgOut(const {%H-}s: string); virtual;    procedure DoDebugLn(const {%H-}s: string); virtual; Put code in there to write to your form, and you can use the entire framework as it is, getting the result in your form. Look at LazLoggerFile, if you need thread safety Do your own unit based on LazLoggerBase, and add initilization 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 initialization  LazDebugLoggerCreator := @CreateYourDebugLogger;  RecreateDebugLogger; ---------------------------------------------------------------------- JimD · 2018-09-04 05:33 Martin_fr, Thank you for the pointers. I do like the idea of leveraging what is already available. I'll experiment with this. All, I updated the original post with the improved Debugln methods and examples from v2.0. I'm doing this mostly for learning, not trying to re-invent the wheel here. As always, constructive feedback is welcome.