Selecting User Function

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:

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.

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 User Function Example section.

A custom function can be selected on the Set Up Function page in the function block editing wizard:

To select a user function:

  1. Select how the unit with function will be used in the drop-down menu of the Select button:

After executing the operations the selected unit will be displayed on the wizard page.

To edit the selected unit, click the Edit button in the unit's drop-down menu. 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 unit's drop-down menu.

  1. Select the user function in the Function drop-down list. The list contains only the unit functions that have the required signature.

  2. 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.

  3. 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 user function is selected that is calculated by the block.

User Function Example

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:

Inserting and Setting Up Function Blocks