To work with the tool in Foresight Analytics Platform 10, use the new interface.

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

A custom function can be selected on the Block Parameters page in the function block editing wizard:

To select a custom function:

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

  1. Select the custom 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 custom function is selected that is calculated by the block.

Custom 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:

Getting Started with the Calculation Algorithms Extension in the Web Application | Inserting and Setting Up Function Blocks