pTAL Reference Manual (G06.24+, H06.09+, J06.03+)

Example 220 Dynamically Selected Procedure Call
LITERAL dev_6530, dev_3270, dev_dove;
INT device_type;
INT param1, param2;
PROC device_6530(i, j);
INT i, j;
EXTERNAL;
PROC device_3270(i, j);
INT i, j;
EXTERNAL;
PROC device_dove(i, j);
INT i, j;
EXTERNAL;
PROCPTR p(i, j);
INT i, j;
END PROCPTR;
CASE device_type of
BEGIN
dev_6530 -> @p := @device_6530;
dev_3270 -> @p := @device_3270;
dev_dove -> @p := @device_dove;
END;
CALL p(param1, param2);
Although you cannot create an array of procedure pointers, you can create a structure that includes
a procedure pointer field. You can choose dynamically which procedure pointer in the structure
array to call.
Example 221 Dynamically Selected Procedure Call
LITERAL dev_6530, dev_3270, dev_dove;
STRUCT s1 [dev_6530:dev_dove]; ! Array of PROCPTRs
BEGIN
PROCPTR d(device, param);
INT device, param;
END PROCPTR;
END;
PROC device_6530(i, j);
INT i, j;
EXTERNAL;
PROC device_3270(i, j);
INT i, j;
EXTERNAL;
PROC device_dove(i, j);
INT i, j;
EXTERNAL;
You must initialize the array s1 to hold the addresses of the procedures that you want to dynamically
call, as in the following example:
@s1[dev_6530].d := @device_6530;
@s1[dev_3270].d := @device_3270;
@s1[dev_dove].d := @device_dove;
Use an index to choose which element of array s1 to call, as in the following example:
CALL s1[dev_6530].d(80, 2);
272 Procedures, Subprocedures, and Procedure Pointers