Whenever you run a procedure, persistent or not, you can retrieve its procedure handle using
the THIS-PROCEDURE system handle. This is useful
when you want to access attributes or methods of the current procedure. There are some
examples of this later in the Useful procedure attributes and methods section.
In most cases, you use procedure handles and the THIS-PROCEDURE system handle
when you run persistent procedures. However, keep in mind that every running procedure,
whether it is persistent or not, has a procedure handle that is held in
THIS-PROCEDURE. A non-persistent procedure can pass
THIS-PROCEDURE as an INPUT parameter to anther
procedure, and the subprocedure can use that value to access internal procedures and
other elements of the parent procedure. This is definitely not the norm for programming
with procedure handles, but you can use it as a way to pass procedures down through a
call stack, as the following example shows. This parent procedure passes its own
procedure handle to another procedure as a parameter:
/* Procedure parentproc.p -- this runs another procedure and passes in its
own procedure handle. */
RUN childproc.p (INPUT THIS-PROCEDURE).
PROCEDURE parentInternal:
DEFINE INPUT PARAMETER cString AS CHARACTER NO-UNDO.
MESSAGE "The child sent the parent " cString VIEW-AS ALERT-BOX.
END PROCEDURE.
The child procedure can then use the parent’s handle to run the internal procedure in the
parent:
/* childproc.p -- called from parentproc.p, it turns around and uses
the parent's procedure handle to run an internal procedure inside it. */
DEFINE INPUT PARAMETER hParent AS HANDLE NO-UNDO.
RUN parentInternal IN hParent (INPUT "this child message").
The result is the following message:
This technique has limited usefulness, because there is no way for the parent to access
internal procedures or other elements of the child procedure it runs. Only the child can
access the parent procedures’s information.