<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, May 17, 2015 at 5:50 AM, Michael Van Canneyt <span dir="ltr"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
Hello,<br>
<br>
As you probably know, it is possible to include source filename, line number, date etc. in your source<br>
with the following directives:<br>
{$I %FILENAME%}<br>
{$I %LINE%}<br>
{$i %DATE%}<br>
<br>
At my request, Florian added<br>
<br>
{$I %CURRENTROUTINE%}<br>
<br>
to the list of possibilities, which means you can do nifty things as:<br>
<br>
program testcr;<br>
<br>
{$mode objfpc}<br>
<br>
Type<br>
TMyClass = Class(TObject)<br>
Public<br>
Procedure MyMethod;<br>
end;<br>
<br>
Var<br>
Indent : Integer;<br>
<br>
Procedure MethodEnter(Const AMethod : String);<br>
begin<br>
Writeln(StringOfChar(' ',Indent),'Entering ',AMethod);<br>
Inc(Indent,2);<br>
end;<br>
<br>
Procedure MethodExit(Const AMethod : String);<br>
begin<br>
Dec(Indent,2);<br>
if Indent<0 then Indent:=0;<br>
Writeln(StringOfChar(' ',Indent),'Exiting ',AMethod);<br>
end;<br>
<br>
Procedure Debug(Const AMsg : String);<br>
<br>
begin<br>
Writeln(StringOfChar(' ',Indent),AMsg);<br>
end;<br>
<br>
Procedure DoSomething;<br>
<br>
Procedure DoNested;<br>
<br>
begin<br>
MethodEnter({$I %CURRENTROUTINE%});<br>
Debug('Nested handling in '+{$I %CURRENTROUTINE%});<br>
MethodExit({$I %CURRENTROUTINE%});<br>
end;<br>
<br>
begin<br>
MethodEnter({$I %CURRENTROUTINE%});<br>
Debug('Doing something in '+{$I %CURRENTROUTINE%}+' at line '+{$I %LINE%});<br>
DoNested;<br>
MethodExit({$I %CURRENTROUTINE%});<br>
end;<br>
<br>
Procedure TMyClass.MyMethod;<br>
<br>
Procedure DoNested;<br>
<br>
begin<br>
MethodEnter({$I %CURRENTROUTINE%});<br>
Debug('Nested handling in '+{$I %CURRENTROUTINE%});<br>
MethodExit({$I %CURRENTROUTINE%});<br>
end;<br>
<br>
begin<br>
MethodEnter({$I %CURRENTROUTINE%});<br>
Debug('Doing some things in '+{$I %CURRENTROUTINE%}+' at line '+{$I %LINE%});<br>
DoNested;<br>
MethodExit({$I %CURRENTROUTINE%});<br>
end;<br>
<br>
<br>
Var<br>
T : TMyClass;<br>
<br>
begin<br>
MethodEnter({$I %CURRENTROUTINE%});<br>
DoSomething;<br>
T:=TMyClass.Create;<br>
try<br>
T.MyMethod;<br>
finally<br>
T.Free;<br>
end;<br>
MethodExit({$I %CURRENTROUTINE%});<br>
end.<br>
<br>
Which produces something like<br>
<br>
Entering $main<br>
Entering DoSomething<br>
Doing something in DoSomething at line 44<br>
Entering DoNested<br>
Nested handling in DoNested<br>
Exiting DoNested<br>
Exiting DoSomething<br>
Entering MyMethod<br>
Doing some things in MyMethod at line 61<br>
Entering DoNested<br>
Nested handling in DoNested<br>
Exiting DoNested<br>
Exiting MyMethod<br>
Exiting $main<br>
<br>
Kudos to Florian.<br>
<br>
Michael.</blockquote></div><div><br></div><div><div>Thanks for this nice feature! =)</div><div><br></div><div>I'll use it in a new logger class that I'm implementing.</div></div><div><br></div><div>(y)</div><div><br></div>-- <br><div class="gmail_signature">Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a></div>
</div></div>