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:
Make sure that you have installed the Calculation Algorithms extension.
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.
To get started with calculation algorithm:
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:
descr. Repository object.
OpenForEdit. Allow or deny to edit repository object.
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 block. It is used to execute calculations by the specified parameters. The ICalcBlock interface is used to work with calculation block.
Aggregation block. It is used to execute aggregation by the specified parameters. The ICalcAggr interface is used to work with aggregation block.
Function block. It is used to calculate application function. The ICalcFunc interface is used to work with function block.
Linear optimization block. It is used to solve the task of optimal use of limited resources. The ICalcLinearOptimizationBlock interface is used to work with linear optimization block.
Control block. It is used to check entered data in the Interactive Data Entry Forms extension. The ICalcValidationBlock interface is used to work with control block.
Ready calculation algorithm. It is used to calculate the existing calculation algorithm in the current calculation. The ICalcAlgorithm interface is used to work with ready calculation algorithm.
Calculation algorithm setup is executed according to the scheme:
For details about interaction of assembly interfaces see the Algo Assembly Hierarchy section.
To create a calculation algorithm object:
In the development environment add a link to the Repository Interaction Unit custom unit contained in the Designer of Business Applications > Common Components component:
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, False, False, Null, True);
// 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.
To get ready calculation algorithm object and work with it:
Get the list of calculation algorithm objects using the ICalcAlgorithm.Items property.
Get the specific calculation algorithm object by index using the ICalcObjectsList.Item property.
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