Function ProcName() Foundation
Retrieves a procedure or function name from the call stack.
ProcName( [<nCallStack>], [<nThreadId>] ) --> cFunctionName
The return value of ProcName() is a character string containing the name of a called function or procedure from the call stack.
The debug function ProcName() provides the name of a procedure or function from the call stack. The call stack contains an entry for each function, procedure, method or code block while the corresponding program code is being processed. When a code block is executed, ProcName() provides the name of the function in which the code block was defined with a prefixed "(B)".
The function ProcName() is used along with the function ProcLine() to determine the location of an error.
// In the example, the return values of ProcName() are
// demonstrated.
PROCEDURE Main
LOCAL cName := ProcName()
? cName // result: MAIN
UserFunc()
RETURN
FUNCTION UserFunc()
? ProcName() // result: USERFUNC
? ProcName(1) // result: MAIN
? ProcName(2) // result: (null string (""))
RETURN NIL
// The example shows a function which writes the call stack
// to a file. This information is very useful in tracking down
// errors if a "fatal error" occurs. See the function
// ErrorBlock() for an example of an extensive error log
// which encompasses more than just the call stack.
FUNCTION WriteCallStack( cFileName )
LOCAL n := 0
SET CONSOLE OFF
SET PRINTER TO (cFileName)
SET PRINTER ON
DO WHILE ! Empty( ProcName(++n) )
? ProcName(n) + "(" + ;
LTrim(Str(ProcLine(n))) + ")"
ENDDO
SET CONSOLE ON
SET PRINTER TO
SET PRINTER OFF
RETURN NIL
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.