How to get current method's name in Delphi 7?

tomazy picture tomazy · Aug 19, 2009 · Viewed 10.2k times · Source

Is there any way to know the name of a method I'm currently in?

So that:

procedure TMyObject.SomeMethod();
begin
  Writeln('my name is: ' + <hocus pocus>); 
end;

would produce this output:

my name is: SomeMethod

Answer

Lars Truijens picture Lars Truijens · Aug 19, 2009

JCL is free and has functions for that. It does depend on how well a stack trace can be made and how much debug information is present.

JclDebug.pas

function FileByLevel(const Level: Integer = 0): string;
function ModuleByLevel(const Level: Integer = 0): string;
function ProcByLevel(const Level: Integer = 0): string;
function LineByLevel(const Level: Integer = 0): Integer;