Developer Function Runtime Behavior (Magic xpa 4.x)
A Developer function is evaluated at runtime like built-in functions.
Function syntax is executed in a manner similar to the execution of a synchronous event handler, where:
Generation = 0 in any task-related function refers to the task that evaluates the function. When a function is set in the parent task and evaluated from the child task, any generation-related calculations done by the function relate to the triggering task as the zero generation. Just like with handlers, any task called from a function is regarded as the child task of the task that evaluated the function.
The variable stack for the function begins from the Main Program to the task evaluating the function.
![](/PublicKnowledge/servlet/rtaImage?eid=ka23z0000004P9F&feoid=00ND0000005rAjf&refid=0EM3z000001rdjF)
|
Once a value is set for a variable in a handler/function, it will remain and will not be cleared in other calls to this handler/function.
|
Generally, all arguments are passed as values to the function. When updating a parameter value, there is no reference for the function to pass back the updated value.
You can pass a variable reference that can be handled by various VAR functions, such as VarCurr and VarSet, or VarCurrN and VarIndex.
As the function is executed, the expression of the returned value is evaluated and the expression evaluator receives the value of that expression as the returned value of the function. If the function has no value set as the returned value, the function returns a Null.
![](/PublicKnowledge/servlet/rtaImage?eid=ka23z0000004P9F&feoid=00ND0000005rAjf&refid=0EM3z000001rdjF)
|
A Developer function can be evaluated by using the EvalStr or EvalStrInfo functions.
For example: Let's say you have a function in the main program that increments its parameter by 1 (without returning a value).
You need to call the function sending a reference to the variable using the VAR literal, for example: increment ('G'VAR)
In the function itself, add a Numeric parameter that is the variable index (varindex), and then you can increment the variable value by using: VarSet(varindex, VarCurr (varindex)+1)
|
If a Developer function is defined for a triggered task that has a handler of an ancestor task triggered from a descendent task, the user-defined task is available for the entire handler execution.
Recursive behavior is when you call the Developer function from another operation defined within the same Developer function. For example, the ABC Developer function has an operation that calls the same Developer function.
![](/PublicKnowledge/servlet/rtaImage?eid=ka23z0000004P9F&feoid=00ND0000005rAjf&refid=0EM3z000001rdjF)
|
Magic xpa does not let a Developer function call a built-in function with the same name.
|
Developer Function Behavior
Defining a Developer Function
Developer Functions and Components