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.
NOTE. If additional parameters are not set in the function signature, but they are set on the Set Up Function page in the function block editing wizard, they will be placed before block parameter values in the parameters variable.
parameters. The array of block parameter values, contents and order of which is set on the Parameters page in the function block editing wizard. Parameter values should be cast to the IDimSelection interface to get dictionary element selections used as block parameters.
The function result can be displayed in the development environment console and used by means of the ITsCalculationContext interface. The function result is not used during algorithm calculation.
To get a function example, see the Custom Function Example section.
A custom function can be selected on the Set Up Function page in the function block editing wizard:
To select a custom function:
Select the unit with function use option:
Select existing repository unit. Select the unit with function in the drop-down list. To quickly search for a unit, start typing its full or partial name.
Create a new unit. To crate a unit, click the Create button. If this option is selected, the development environment page opens to create a unit containing the required function signature. Creating a new unit is available if the existing unit is not selected in the drop-down list.
After executing the operations the selected unit will be displayed on the wizard page.
To edit the selected unit, click the Edit button. After executing the operation the development environment page opens to edit the unit.
To cancel the use of the selected unit, click the Delete button in the drop-down list.
Select the custom 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 using the Check Syntax button. If everything is set up correctly, the appropriate message is displayed, otherwise an error message is displayed.
As a result, the custom 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. The DBMS command contains parameters, which identifiers match with identifiers of the dictionaries used as function block parameters.
To execute the example, add links to the Db, Dimensions, Metabase, Ui system assemblies.
Public Function callDBCommand(Command: Integer; Paramarray parameters: Array Of Variant): Variant;
Var
Desc: IMetabaseObjectDescriptor;
ComInst: ISQLCommandInstance;
i: integer;
Prms: IMetabaseObjectParamValues;
Prm: IMetabaseObjectParamValue;
Sel: IDimSelection;
Begin
// Execute operations if confirmation dialog box opens with specified message
If WinApplication.ConfirmationBox("Calculation may take long time. Continue?") Then
// Get DBMS command
Desc := MetabaseClass.Active.Item(Command);
// Create a copy of DBMS command parameters with empty values
Prms := Desc.Params.CreateEmptyValues;
// Fill in copy of DBMS command parameters with parameters from block
For i := 0 To parameters.Length - 1 Do
// Get function block parameter value
Sel := parameters[i];
// Display parameter value in the console
Debug.Writeline(Sel.ToString);
// Get DBMS command parameter by identifier of the dictionary used as block parameter
Prm := Prms.FindById(Sel.Dimension.Ident);
// Assign block parameter value to DBMS command parameter value
If Prm <> Null Then
Prm.Value := Sel.ToVariant;
End If;
End For;
// Open DBMS command with obtained parameter values from block
ComInst := Desc.Open(Prms) As ISQLCommandInstance;
// Start DBMS command for execution
ComInst.Execute;
End If;
Return 0;
End Function callDBCommand;
After the function is executed, execution of the DBMS command is started with parameters, which values were obtained from the function block. Values of the obtained parameters will be displayed in the console.
See also: