Sometimes it is useful to call a procedure with a function pointer. One example would be calling a unique procedure for each Test defined in a Program based on the Test and Task name of the current Test being executed. A procedure pointer can be used instead of hard coding a call to each procedure, thereby simplifying the code and allowing more tests to be added without code modification.
The following steps should be followed:
- Create procedures for each test defined in the program. In this example, the procedure names must be the Task name followed with the underscore character, appended to the Test name follwed by “_Init”. This naming template can be changed by modifying the first line of code in step 3.
- Define a variable in the OnInitTest() event named proc of type Procedure. This will act as the function pointer.
- Insert the following code in the OnInitTest() event.
proc=Task.Name+"_"+Test.Name+"_Init" !Assign the procedure pointer a procedure
if(proc) !Check to make sure the procedure actually exists
proc() !Execute procedure
else
print "proc is not valid!"
!error handling code
endif