Getting method name

Is there a way to pass the name of the currently executing method to another routine as a parameter? For example, if I have a global routine that puts up a message box that says xxx routine did something, how do I pass the calling method name so the ‘xxx’ has the calling method’s name?

I’ve search the forums but can’t seem to find the information.

  • Dale

Would be cool if there were a pragma for this… But there’s an easy approach. Raise an exception in a “try” block, catch the exception, peel the name off the stack. Something like:

Sub MyReportingMethod try raise new RuntimeException catch err as RuntimeException // err.stack(1) or err.stack(err.stack.Ubound - 1) has the calling method end try end MyReportingMethod

You’ll need to have IncludeFunctionNames checked in your build settings.

Sounds like you want the CurrentMethodName method.

Or you could use CurrentMethodName. :slight_smile:

http://documentation.xojo.com/index.php?title=CurrentMethodName&oldid=37682

D’OH, Andrew beat me to it.

Well, then he has to pass it as a parameter. He actually needs the method calling the current method. But yeah, that could work with a parameter.

Yeah there’s no “who called me” … you know that :slight_smile:

Thanks, everyone. Actually passing the method name as a parameter will work just fine for what I need.

  • Dale