IAlgorithmCalculationExecutor.Run

Syntax

Run: IAlgorithmCalculationResult;

Description

The Run method executes algorithm.

Example

Executing the example requires that the repository contains a calculation algorithm with the ALGORITHM identifier. Calculation blocks should be created in the calculation algorithm.

Add links to the Algo, Metabase system assemblies. Add links to the assemblies required for working with calculation algorithms.

Sub UserProc;
Var
    MB: IMetabase;
    MObj: IMetabaseObjectDescriptor;
    Algo: ICalcObject;
    CalcAlgo: ICalcAlgorithm;
    CalcAlgoExecuter: IAlgorithmCalculationExecutor;
    HasCalcBlocks: Boolean;
    CalcObject: ICalcObject;
    i: Integer;
    CalcResult: IAlgorithmCalculationResult;
Begin
    MB := MetabaseClass.Active;
    // Get calculation algorithm
    MObj := MB.ItemById("ALGORITHM");
    Algo := CalcObjectFactory.CreateCalcObject(MObj, True);
    CalcAlgo := Algo As ICalcAlgorithm;
    // Create an object to check if there are calculation objects by their type
    CalcAlgoExecuter := CalcObjectFactory.CreateCalculationExecutor(MObj);
    HasCalcBlocks := CalcAlgoExecuter.HasObjectByType(CalcObjectType.CalcBlock);
    Debug.WriteLine("Indicates whether algorithm contains calculation blocks: " + HasCalcBlocks.ToString);
    // If algorithm contains calculation blocks, display list of their names in the console and calculate algorithm
    If HasCalcBlocks Then
        Debug.WriteLine("List of calculation algorithm block names:");
        For i := 0 To CalcAlgo.Items.Count - 1 Do
            CalcObject := CalcAlgo.Items(i);
            If CalcObject.Type = CalcObjectType.CalcBlock Then
                Debug.WriteLine("  " + i.ToString + ") " + (CalcObject As ICalcBlock).Name);
            End If;
        End For;
        Debug.WriteLine("Calculate algorithm:");
        CalcResult := CalcAlgoExecuter.Run;
        Debug.WriteLine("  Calculation is finished in " + CalcResult.TotalElapsedMilliseconds.ToString + " ms");
    End If;
End Sub UserProc;

During the execution, the system checks if the algorithm contains calculation blocks. If the algorithm contains calculation blocks, their names are displayed in the development environment console and after this the algorithm will be calculated.

See also:

IAlgorithmCalculationExecutor