User guide

30
VTB USER GUIDE
6.10 Delegates
This type of variables is used to call a function by a variable. First of all the address of the function to call must be written
in the DELEGATE variable. Then we can use this variable to call the function with the instruction call_delegate. It can
also be created an array of DELEGATE variables and then call a function according to the index of the delegate.
Using of DELEGATES is very powerful because it allows the access to the functions in the fastest way without writing a
long series of conditional cycles.
WARNING: The function called by CALL_DELEGATE must be VOID both for arguments and return parameter.
VTB doesn't make any control to the initialization of the DELEGATE. Calling a delegate not initialized can go the system
in CRASH
Example:
Used variables:
var(2) as delegate
Page Init of Main task (delegates initialization):
Var(0)=fun1 ¢ assign to var(0) the address of function fun1
Var(1)=fun2 ¢ assign to var(1) the address of function fun2
Page Function of Main task (functions declaration):
Function fun1() as void
.
Endfunction
Function fun2() as void
.
Endfunction
Master Ciclo of Main task (calling of functions by delegates):
Call_delegate var(0) fun1 will run
Call_delegate var(1) fun2 will run