pTAL Guidelines for TAL Programmers
Differences Between TAL and pTAL
pTAL Guidelines for TAL Programmers—527256-002
3-19
Dynamically Selected Procedure Calls
All of the examples:
•
Have calls based on the device type of a terminal
•
Use these declarations:
LITERAL dev_6530, dev_3270, dev_conv;
INT device_type;
PROCPTR p(i, j);
INT i, j;
END PROCPTR;
PROC device_6530(i, j); INT i, j; EXTERNAL;
PROC device_3270(i, j); INT i, j; EXTERNAL;
PROC device_conv(i, j); INT i, j; EXTERNAL;
You cannot create an array of procedure pointers, but you can create an array of
structures that have procedure pointer fields and then choose dynamically which
procedure pointer in the array to call, as in Example 3-12 on page 3-19.
Example 3-12. Procedure Pointer in a Array of Structures
Declare an array of structures that contain one procedure pointer field:
STRUCT s1[dev_6530:dev_conv]; ! Array of structures
BEGIN
PROCPTR d(dev, param); ! Procedure pointer field
INT dev, param;
END PROCPTR;
END;
Initialize the procedure pointer fields:
@s1[dev_6530].d := @device_6530;
@s1[dev_3270].d := @device_3270;
@s1[dev_conv].d := @device_conv;
Use an index to choose an element of array s1 to call:
CALL s1[dev_6530].d(80, 2);
Example 3-13. Procedure Pointers in a CASE Statement
CASE device_type OF
BEGIN
dev_6530 -> @p := @device_6530;
dev_3270 -> @p := @device_3270;
dev_conv -> @p := @device_conv;
END;
CALL p(1, 2);