In this article:

Getting Started with Calculation Algorithm

Creating a Calculation Algorithm Object

Getting Ready Calculation Algorithm Object

General Programming Principles Using the Algo Assembly

The Algo assembly is used to work with the Calculation Algorithms extension. Programming in Fore using this assembly consists in a consecutive setup of calculation algorithm.

Before getting started with calculation algorithm:

  1. Make sure that you have installed the Calculation Algorithms extension.

  2. In the development environment add links to the Algo system assembly and to the Calculation Algorithm Core custom assembly, which is included in the Calculation Algorithms component:

After the operations are executed, classes and application functions of the Calculation Algorithm Core custom assembly are available to get started with calculation algorithm.

Getting Started with Calculation Algorithm

To get started with calculation algorithm:

  1. Get a repository object of the Indicators Calculation Algorithm type using the CalcObjectFactory class and the CreateCalcObject application function, which are implemented in the Calculation Algorithm Core custom assembly.

Syntax of the CreateCalcObject function:

CreateCalcObject(descr: IMetabaseObjectDescriptor, [OpenForEdit: Boolean = true]): ICalcObject;

Parameters:

  1. Cast the obtained object to the ICalcAlgorithm interface.

The example of getting calculation algorithm with the ALGORITHM identifier for edit:

Sub UserProc;
Var
    MB: IMetabase;
    MObj: IMetabaseObjectDescriptor;
    Algo: ICalcObject;
    CalcAlgo: ICalcAlgorithm;
Begin
    MB := MetabaseClass.Active;
    MObj := MB.ItemById(
"ALGORITHM");
    Algo := CalcObjectFactory.CreateCalcObject(MObj, 
True);
    CalcAlgo := Algo 
As ICalcAlgorithm;
    
//...
End Sub UserProc;

The following objects are used in calculation algorithm setup:

Calculation algorithm setup is executed according to the scheme:

For details about interaction of assembly interfaces see the Algo Assembly Hierarchy section.

Creating a Calculation Algorithm Object

To create a calculation algorithm object:

  1. In the development environment add a link to the Repository Interaction Unit custom unit contained in the Designer of Business Applications > Common Components component:

  1. Create an object using the connected unit:

Sub UserProc;
Var
    MB: IMetabase;
    Descr,MObjAlgo: IMetabaseObjectDescriptor;
    Block: ICalcFunc;
    Algo, CalcObject: ICalcObject;
    List: ICalcObjectsList;
    CalcAlgo: ICalcAlgorithm;
    ObjectType: IMetabaseCustomClass;
Begin
    MB := MetabaseClass.Active;
    
// Get calculation algorithm, to which an object will be added
    MObjAlgo := MB.ItemById("<calculation algorithm identifier>");
    Algo := CalcObjectFactory.CreateCalcObject(MObjAlgo, 
True);
    CalcAlgo := Algo 
As ICalcAlgorithm;
    
// Set object type
    ObjectType := GetMetabaseHelper.GetCustomClassByEnum(BPClasses.<object type>);
    Descr := GetMetabaseHelper.CreateObjectDescriptor(ObjectType.ClassId, ObjectType.Name, 
"", CalcAlgo.Descriptor, FalseFalseNullTrue);
    
// Create an object of the specified type
    CalcObject := New <object class>.Create(Descr);
    
// Cast the obtained object to corresponding interface
    Block := CalcObject As <interface>;
    
//...
    // Further object setup
    //...

    // Save object
    CalcObject.SaveObject;
    
// Get list of algorithm objects
    List := CalcAlgo.Items;
    
// Add the created object to algorithm
    List.Add(CalcObject);
    
// Save changes in calculation algorithm
    CalcAlgo.SaveObject;
End Sub UserProc;

In the <object type>, <object class>, <interface> substitutions set interrelated values corresponding to the object:

Object Substitutions Values
Calculation block <object type> Calc_Block
<object class> CalcBlockClass
<interface> ICalcBlock
Aggregation block <object type> Aggr_Block
<object class> CalcAggrClass
<interface> ICalcAggr
Function Block <object type> Func_Block
<object class> CalcFuncClass
<interface> ICalcFunc
Linear aggregation block <object type> LinearOptimization
<object class> CalcLinearOptimizationBlock
<interface> ICalcLinearOptimizationBlock
Control block <object type> Validation_Block
<object class> CalcValidationBlockClass
<interface> ICalcValidationBlock
Ready calculation algorithm <object type> Algorithm
<object class> CalcAlgorithmClass
<interface> ICalcAlgorithm

After executing the operations, an object with the specified settings is created in the calculation algorithm.

Getting Ready Calculation Algorithm Object

To get ready calculation algorithm object and work with it:

  1. Get the list of calculation algorithm objects using the ICalcAlgorithm.Items property.

  2. Get the specific calculation algorithm object by index using the ICalcObjectsList.Item property.

  3. Cast the obtained object to the interface of the corresponding object type: ICalcBlock, ICalcAggr, ICalcFunc, ICalcLinearOptimizationBlock, ICalcValidationBlock, ICalcAlgorithm.

After executing the operations, the obtained object can be set up and worked with.

The example of getting ready calculation block in the algorithm with the ALGORITHM identifier:

Sub UserProc;
Var
    MB: IMetabase;
    MObj: IMetabaseObjectDescriptor;
    Algo, CalcBlock: ICalcObject;
    List: ICalcObjectsList;
    CalcAlgo: ICalcAlgorithm;
    Block: ICalcBlock;
Begin
    
MB := MetabaseClass.Active;
    
// Get calculation algorithm
    MObj := MB.ItemById("ALGORITHM");
    Algo := CalcObjectFactory.CreateCalcObject(MObj, 
True);
    CalcAlgo := Algo 
As ICalcAlgorithm;
    
// Get list of calculation algorithm objects
    List := CalcAlgo.Items;
    
// Get calculation block
    CalcBlock := List.Item(0);
    Block := CalcBlock 
As ICalcBlock;
    
//...
End Sub UserProc;

Getting ready calculation block is also given in the example for ICalcBlock.StubOut, getting linear optimization block is given in the example for ICalcLinearOptimizationBlock.StubCoefficient.

See also:

About the Algo Assembly | Algo Assembly Interfaces | Algo Assembly Enumerations