How Do I Create a Function? (Magic xpa 4.x)
![](/PublicKnowledge/servlet/rtaImage?eid=ka23z0000004PI0&feoid=00ND0000005rAjf&refid=0EM3z000001rdtZ)
In Magic xpa, a function is just a special type of logic unit. Functions use the same input parameters, local variables, and the same operations that are available for the other logic units. One main difference is that they have a return value, so that when a function is used in an expression or on a form, the value can be used directly in the expression without using a variable to hold a parameter.
For instance, in this example, we have a function that formats a date into a complex formatted string for reports. The formatted string can be used directly on the form, by using the function in an expression.
The other difference is that your functions show up on the Function List right along with all the built-in Magic xpa functions, complete with a list of the expected parameters. This makes them easy to find and to use. This also means that if you name your function the same as a built-in function, you can override the built-in function. So if you want to extend or change a built-in function, you can.
Below is a summary of how to create a function.
The scope of a function depends on where it is located, and on the value of the Scope property of the function.
-
If the function is in a task and the Scope is set to Task, then the function will only be visible for that task.
-
If the function is in a parent task, and the Scope is set to Subtask, then the function will be visible for all subtasks. Therefore, if the function is in the Main Program, it will be visible for the entire application.
-
If the function is part of a component, then it can be shared across many projects.
![](/PublicKnowledge/servlet/rtaImage?eid=ka23z0000004PI0&feoid=00ND0000005rAjf&refid=0EM3z000001rdtU)
-
Go to the Logic section of your task.
-
Press Ctrl+H to open up a header line.
-
Type F to make this a function. The cursor will move to the right, into the Function Name field.
-
Type in your name for this function. You can use any name, but if you use the name of an existing Magic xpa function, then you will override the function provided by Magic xpa.
-
Create your input and output parameters, if any (see How Do I Set the Function’s Parameters? for details on how to do this).
-
Create your return values (see How Do I Set the Return Value of a Function? for details on how to do this).
Now you have created a function! The function will show up on the Function List with all the built-in Magic xpa functions, which makes it easy to use.
How Do I Create a Function That is Available for the Current Task Only?
How Do I Create a Function That is Available For the Entire Project?
The Online and Rich Client Samples projects (program LG01 and RLG01)