ICalcObjectsList.RefreshObject

Syntax

RefreshObject(CalcObject: ICalcObject);

Parameters

CalcObject. Calculation algorithm object.

Description

The RefreshObject method refreshes the specified object in the collection.

Comments

It may be required to update the object in the collection if the algorithm uses the existing block from the repository, and block settings are changed outside the calculation algorithm.

Example

Executing the example requires that the repository contains two calculation algorithms with the ALGORITHM1 and ALGORITHM2 identifiers. Besides, a calculation block with the CALC_BLOCK identifier is created in the repository. This block is used in algorithms.

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

Sub UserProc;
Var
    MB: IMetabase;
    MObjAlg1, MObjAlg2, MObjCalcBlock: IMetabaseObjectDescriptor;
    Algo1, Algo2, CalcObj: ICalcObject;
    FirstCalcAlgo, SecondCalcAlgo: ICalcAlgorithm;
    ListAlg1, ListAlg2: ICalcObjectsList;
    CalcBlock: ICalcBlock;
    Index: Integer;
Begin
    MB := MetabaseClass.Active;
    // Get the first calculation algorithm
    MObjAlg1 := MB.ItemById("ALGORITHM1");
    Algo1 := CalcObjectFactory.CreateCalcObject(MObjAlg1, True);
    FirstCalcAlgo := Algo1 As ICalcAlgorithm;
    // Get the second calculation algorithm
    MObjAlg2 := MB.ItemById("ALGORITHM2");
    Algo2 := CalcObjectFactory.CreateCalcObject(MObjAlg2, True);
    SecondCalcAlgo := Algo2 As ICalcAlgorithm;
    // Edit one common block and refresh it in algorithms for the changes to be applied
    MObjCalcBlock := MB.ItemById("CALC_BLOCK");
    CalcObj := CalcObjectFactory.CreateCalcObject(MObjCalcBlock, True);
    CalcBlock := CalcObj As ICalcBlock;
    // Rename
    CalcBlock.Name := "Calculation block (refreshed)";
    // Refresh block in calculation algorithms
    RefreshCalcObjInAlg(FirstCalcAlgo, CalcBlock);
    RefreshCalcObjInAlg(SecondCalcAlgo, CalcBlock);
    // Check if changes are applied
    ListAlg1 := FirstCalcAlgo.Items;
    ListAlg2 := SecondCalcAlgo.Items;
    Index := ListAlg1.IndexOf(CalcBlock);
    Debug.WriteLine("Calculation block name in the first algorithm: " + ListAlg1.Item(Index).Name);
    Index := ListAlg2.IndexOf(CalcBlock);
    Debug.WriteLine("Calculation block name in the second algorithm: " + ListAlg2.Item(Index).Name);
    // Save algorithms
    FirstCalcAlgo.SaveObject;
    SecondCalcAlgo.SaveObject;
End Sub UserProc;

Private Sub RefreshCalcObjInAlg(Algo: ICalcAlgorithm; CalcObj: ICalcObject);
Var
    ListAlg: ICalcObjectsList;
Begin
    ListAlg := Algo.Items;
    // If algorithm contains the block, refresh it
    If ListAlg.IsContain(CalcObj) Then
        ListAlg.RefreshObject(CalcObj);
    End If;
End Sub RefreshCalcObjInAlg;

After executing the example, object chains of both calculation algorithms are compared. If the chains do not match, the required objects will be added to corresponding calculation algorithms.

See also:

ICalcObjectsList