A function determines how a block will be calculated. A function should be written in a Fore unit and should have the following structure:
Public Function <Function name>([<additional parameters>,]Paramarray parameters: Array Of Variant): Variant;
Where:
[<additional parameters>,]. Constant custom parameters that can additionally manage function calculation. If there are several parameters, they are specified via comma. May be missing.
parameters. The list of block parameter values, contents and order of which is set on the Parameters page in the function block editing wizard.
To get a function example, see the User Function Example section.
A user function can be selected on the Block Parameters page in the function block editing wizard:
To select a user function:
Select a unit with the function or an assembly containing a unit with the function in the Unit drop-down list. The unit or assembly should be written in the Fore language. To view selected unit or form in the development environment, click the Open button.
TIP. To create a unit containing the required function signature, click the Create button. The dialog box opens where unit storing location can be selected and determine its name and identifier. After that the unit will be opened in the development environment.
Select the user function in the Function drop-down list. The list contains only the unit functions that have the required signature.
If constant custom parameters are determined in the function signature, set their values in the Additional Parameter Values box. If there are several parameters, their values should be entered via comma. String parameters should be entered in quotation marks.
Check if function parameters are set correctly. Click the Check Syntax button. If everything is set up correctly, the appropriate message appears, otherwise an error message appears.
As a result, the user function is selected that is calculated by the block.
The example shows executing a DBMS command, which key is sent as a constant custom parameter.
To execute the example, add links to the Db, Metabase, Ui system assemblies.
Public Function callDBCommand(Command: Integer; Param: Array Of Variant): Variant;
Var
comInst: ISQLCommandInstance;
Begin
If WinApplication.ConfirmationBox("Calculation may take a long time. Continue?") Then
comInst := MetabaseClass.Active.Item(Command).Open(Null) As ISQLCommandInstance;
comInst.Execute;
End If;
Return 0;
End Function callDBCommand;
See also: