Reputation: 1367
I'm trying to write some testing programs and I have an idea to run a procedure, and have the procedure call internal functions and procedures in the calling program. As I understand it, you can use RUN x IN y
where y is any procedure in the calling stack.
However, I can't seem to find any way of getting the handle for the calling procedure. There doesn't seem to be a means of moving up the call stack.
The only way I can think of doing it is by passing the calling procedure's THIS-PROCEDURE
handle as a parameter. It would work, but seems rather inelegant.
Upvotes: 4
Views: 3424
Reputation: 3251
To get the handle of the calling procedure, use the SOURCE-PROCEDURE handle. It has the handle for the last procedure call. If another procedure is run, then it will change to match that procedure instance's handle, so if you need your program to remember who called it, your code'll need to store that value immediately when it's called.
Upvotes: 1
Reputation: 8011
You are almost there. Take a look at the example below utilizing the THIS-PROCEDURE:INSTANTIATING-PROCEDURE handle.
INSTANTIATING-PROCEDURE attribute
Returns the handle to the procedure in which an object was instantiated.
parentProgram.p
RUN childProgram.p.
PROCEDURE hello:
DEFINE INPUT PARAMETER pcMessage AS CHARACTER NO-UNDO.
MESSAGE "Child says:" pcMessage VIEW-AS ALERT-BOX INFORMATION.
END.
childProgram.p
MESSAGE "Calling parent. Anybody home?" VIEW-AS ALERT-BOX.
IF VALID-HANDLE(THIS-PROCEDURE:INSTANTIATING-PROCEDURE) THEN
RUN hello IN THIS-PROCEDURE:INSTANTIATING-PROCEDURE (INPUT "I am your child") NO-ERROR.
IF ERROR-STATUS:ERROR THEN DO:
MESSAGE "That didn't work" VIEW-AS ALERT-BOX ERROR.
END.
Upvotes: 2