I suppose you could do it that way, but isn't there a better way? I'd like to minimize extra work but this function is important in maintaining a large project.
Please?
Main Topics
Browse All TopicsIs there a way in Delphi (Developer Studio 2006) to grab the name of a procedure or function for logging purposes? example:
function MyMultiply(x, y: Integer): Integer;
var Mystring: String;
begin
result:=x*y;
MyString:= // something here that returns 'MyMultiply'
LogThis('Function Called: '+MyString);
end;
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Yes, there is a way. The following code will get the memory address of the routine that calls Log. When you call a function or procedure, the return address is placed on the stack. Log pulls this off the stack, and sends it to the LogAddress procedure through the EAX register. LogAddress needs some work (I'll explain in a moment what needs to be done), but for now it will just show you the address of the where Log was called. To use it, all you need to do is call Log anywhere in your application, be it in a class, function, procedure, whereever.
procedure LogAddress(ptr: pointer);
begin
ShowMessage(inttoHex(integ
end;
procedure Log;
begin
asm
pop EAX
push EAX
call LogAddress
end;
end;
procedure MyProc;
begin
Log;
end;
procedure TForm3.Button1Click(Sender
begin
Log;
end;
procedure TForm3.FormCreate(Sender: TObject);
begin
Log;
MyProc;
end;
Now, to make the address usable, you need to replace the ShowMessage code in LogAddress with code that looks up the address in the detailed map file. You generate a detailed map file under the Project | Options | Linker menu option in Delphi. In this same dialog you'll notice an image base value that defaults to $00400000. To make sense of the map file, you take this image base value, add $1000, and that's the address needed to look up the value in the map file. To see that this works, pull up the Windows calculator, using the scientific mode (so you can use hex addresses), and do the math using the show message data. You'll find that you can not only locate the routine that called it, you can even locate the line of code following where the Log statement is called. Note that the map file must be up to date for this to work, so you must do a build all for these addresses to be in sync.
Business Accounts
Answer for Membership
by: TNamePosted on 2007-05-26 at 06:05:03ID: 19161806
I guess simply hardcoding it not an option?
E.g.:
function MyMultiply(x, y: Integer): Integer;
const Mystring = 'MyMultiply';
begin
result:=x*y;
LogThis('Function Called: '+MyString);
end;