Re: [Lazarus] New preprocessor directive
On Sun, May 17, 2015 at 5:50 AM, Michael Van Canneyt mich...@freepascal.org wrote: Hello, As you probably know, it is possible to include source filename, line number, date etc. in your source with the following directives: {$I %FILENAME%} {$I %LINE%} {$i %DATE%} At my request, Florian added {$I %CURRENTROUTINE%} to the list of possibilities, which means you can do nifty things as: program testcr; {$mode objfpc} Type TMyClass = Class(TObject) Public Procedure MyMethod; end; Var Indent : Integer; Procedure MethodEnter(Const AMethod : String); begin Writeln(StringOfChar(' ',Indent),'Entering ',AMethod); Inc(Indent,2); end; Procedure MethodExit(Const AMethod : String); begin Dec(Indent,2); if Indent0 then Indent:=0; Writeln(StringOfChar(' ',Indent),'Exiting ',AMethod); end; Procedure Debug(Const AMsg : String); begin Writeln(StringOfChar(' ',Indent),AMsg); end; Procedure DoSomething; Procedure DoNested; begin MethodEnter({$I %CURRENTROUTINE%}); Debug('Nested handling in '+{$I %CURRENTROUTINE%}); MethodExit({$I %CURRENTROUTINE%}); end; begin MethodEnter({$I %CURRENTROUTINE%}); Debug('Doing something in '+{$I %CURRENTROUTINE%}+' at line '+{$I %LINE%}); DoNested; MethodExit({$I %CURRENTROUTINE%}); end; Procedure TMyClass.MyMethod; Procedure DoNested; begin MethodEnter({$I %CURRENTROUTINE%}); Debug('Nested handling in '+{$I %CURRENTROUTINE%}); MethodExit({$I %CURRENTROUTINE%}); end; begin MethodEnter({$I %CURRENTROUTINE%}); Debug('Doing some things in '+{$I %CURRENTROUTINE%}+' at line '+{$I %LINE%}); DoNested; MethodExit({$I %CURRENTROUTINE%}); end; Var T : TMyClass; begin MethodEnter({$I %CURRENTROUTINE%}); DoSomething; T:=TMyClass.Create; try T.MyMethod; finally T.Free; end; MethodExit({$I %CURRENTROUTINE%}); end. Which produces something like Entering $main Entering DoSomething Doing something in DoSomething at line 44 Entering DoNested Nested handling in DoNested Exiting DoNested Exiting DoSomething Entering MyMethod Doing some things in MyMethod at line 61 Entering DoNested Nested handling in DoNested Exiting DoNested Exiting MyMethod Exiting $main Kudos to Florian. Michael. Thanks for this nice feature! =) I'll use it in a new logger class that I'm implementing. (y) -- Silvio Clécio My public projects - github.com/silvioprog -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] New preprocessor directive
On 2015-05-17 14:23, Martin Frb wrote: Simply use $ProcedureName() in your template EnterSomething('$ProcedureName()'); That is what I've been using up to now, but is problematic if you switch between IDE's or programmer editors to do coding (I do this often). At least the new directive will be universally supported. Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] New preprocessor directive
On 2015-05-17 10:22, Florian Klämpfl wrote: A profiler should use debug info imo. True, but the fpprofiler is a quick and easy one (though basic), if no others are available. Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] New preprocessor directive
On 2015-05-17 09:50, Michael Van Canneyt wrote: At my request, Florian added {$I %CURRENTROUTINE%} Oh wow, that will be super handy! (For the fpprofiler too.) Many thanks for that one. Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] New preprocessor directive
Am 17.05.2015 um 10:50 schrieb Michael Van Canneyt: Hello, As you probably know, it is possible to include source filename, line number, date etc. in your source with the following directives: {$I %FILENAME%} {$I %LINE%} {$i %DATE%} At my request, Florian added {$I %CURRENTROUTINE%} to the list of possibilities, which means you can do nifty things as: program testcr; {$mode objfpc} Type TMyClass = Class(TObject) Public Procedure MyMethod; end; Var Indent : Integer; Procedure MethodEnter(Const AMethod : String); begin Writeln(StringOfChar(' ',Indent),'Entering ',AMethod); Inc(Indent,2); end; Procedure MethodExit(Const AMethod : String); begin Dec(Indent,2); if Indent0 then Indent:=0; Writeln(StringOfChar(' ',Indent),'Exiting ',AMethod); end; Procedure Debug(Const AMsg : String); begin Writeln(StringOfChar(' ',Indent),AMsg); end; Procedure DoSomething; Procedure DoNested; begin MethodEnter({$I %CURRENTROUTINE%}); Debug('Nested handling in '+{$I %CURRENTROUTINE%}); MethodExit({$I %CURRENTROUTINE%}); end; begin MethodEnter({$I %CURRENTROUTINE%}); Debug('Doing something in '+{$I %CURRENTROUTINE%}+' at line '+{$I %LINE%}); DoNested; MethodExit({$I %CURRENTROUTINE%}); end; Procedure TMyClass.MyMethod; Procedure DoNested; begin MethodEnter({$I %CURRENTROUTINE%}); Debug('Nested handling in '+{$I %CURRENTROUTINE%}); MethodExit({$I %CURRENTROUTINE%}); end; begin MethodEnter({$I %CURRENTROUTINE%}); Debug('Doing some things in '+{$I %CURRENTROUTINE%}+' at line '+{$I %LINE%}); DoNested; MethodExit({$I %CURRENTROUTINE%}); end; Var T : TMyClass; begin MethodEnter({$I %CURRENTROUTINE%}); DoSomething; T:=TMyClass.Create; try T.MyMethod; finally T.Free; end; MethodExit({$I %CURRENTROUTINE%}); end. At least it looks as ugly as possible so nobody will use this too much :) -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] New preprocessor directive
Am 17.05.2015 um 10:54 schrieb Graeme Geldenhuys: On 2015-05-17 09:50, Michael Van Canneyt wrote: At my request, Florian added {$I %CURRENTROUTINE%} Oh wow, that will be super handy! (For the fpprofiler too.) A profiler should use debug info imo. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] New preprocessor directive
On Sun, 17 May 2015, Florian Klämpfl wrote: Am 17.05.2015 um 10:50 schrieb Michael Van Canneyt: Hello, At least it looks as ugly as possible so nobody will use this too much :) Agreed that it is ugly, but indispensibe when programming webservers. Michael.-- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] New preprocessor directive
At my request, Florian added {$I %CURRENTROUTINE%} to the list of possibilities, which means you can do nifty things as: I usually use hardcoded strings for that, so this makes my coding life easier :) Thanks! -- View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-New-preprocessor-directive-tp4042241p4042246.html Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] New preprocessor directive
Add I created code template for it: icr and it writes {$I %CURRENTROUTINE%} itself :-) V. __ Od: leledumbo leledumbo_c...@yahoo.co.id Komu: lazarus@lists.lazarus.freepascal.org Datum: 17.05.2015 13:54 Předmět: Re: [Lazarus] New preprocessor directive At my request, Florian added {$I %CURRENTROUTINE%} to the list of possibilities, which means you can do nifty things as: I usually use hardcoded strings for that, so this makes my coding life easier :) Thanks! -- View this message in context: http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-New-preprocessor-directive-tp4042241p4042246.html http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-New-preprocessor-directive-tp4042241p4042246.html Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] New preprocessor directive
On 17/05/2015 13:22, Vojtěch Čihák wrote: Add I created code template for it: icr and it writes{$I %CURRENTROUTINE%} itself :-) Simply use $ProcedureName() in your template EnterSomething('$ProcedureName()'); Of course it does not update if you rename the procedure, but otherwise it is fine. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus