Hi,
Is it possible to determine the name of a procedure or function that is running?
(For you C programmers, something akin to the __FUNCTION__
macro)
I’ve gone through Info("ProcedureStack")
, but it, unfortunately, does not include the original caller in its stack.
Scenario #1
If:
ProcedureA calls ProcedureB
Then:
Info("ProcedureStack") in ProcedureB returns "ProcedureB"
Expected result: Info("ProcedureStack")
, when called from ProcedureB, includes ProcedureA and ProcedureB.
Scenario #2
If:
ProcedureA calls ProcedureB which calls ProcedureC
Then:
Info("ProcedureStack") in ProcedureC, returns "ProcedureB" and "ProcedureC"
Expected result: Info("ProcedureStack")
, when called from ProcedureC, includes ProcedureA, ProcedureB, and ProcedureC.
Unfortunately, CallingProcedure()
also does not return what’s expected.
Scenario #3
If:
ProcedureA calls ProcedureB
Then:
CallingProcedure() in ProcedureB returns an empty string
Expected result: CallingProcedure()
, when called from ProcedureB, returns ProcedureA.
Scenario #4
If:
ProcedureA calls ProcedureB, which calls ProcedureC
Then:
CallingProcedure() in ProcedureC returns "ProcedureB"
Expected result: Exactly what happens. (IOW, this works)
Next to “CallingProcedure()”, it’d be nice to have something like “CurrentProcedure()” that returns info about the currently running procedure or function.
Why would I want this? Glad you asked …
I’ve got a very simple logging function that writes information to a log file as the program runs.
It would be nice if each statement could automagically write out the procedure name without requiring the calling procedure to provide the procedure/function name in a FileGlobal
variable.
Thanks for listening …