FindByMetaModelKey(Key: Integer): ICalcObject;
Key. Metamodel key.
The FindByMetaModelKey method searches for object in the collection by metamodel key.
Executing the example requires that the repository contains two calculation algorithms with the ALGORITHM1 and ALGORITHM2 identifiers. The algorithms are based on blocks in the repository.
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: IMetabaseObjectDescriptor;
Algo1, Algo2: ICalcObject;
FirstCalcAlgo, SecondCalcAlgo: ICalcAlgorithm;
ListAlg1, ListAlg2: ICalcObjectsList;
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;
// Lists of objects of the first and the second algorithms
ListAlg1 := FirstCalcAlgo.Items;
ListAlg2 := SecondCalcAlgo.Items;
// Check if calculation chains of algorithms match
If CalculationChainSeqCompare(ListAlg1, ListAlg2) Then
Debug.WriteLine("Sequence of calculation chains is equal");
Else
// If sequence does not match, transfer missing blocks from the first algorithm to the second algorithm and back
Debug.WriteLine("Sequence of calculation chains is not equal");
AddBlocks(ListAlg1, ListAlg2);
FirstCalcAlgo.SaveObject;
SecondCalcAlgo.SaveObject;
End If;
End Sub UserProc;
Private Function CalculationChainSeqCompare(ListAlg1: ICalcObjectsList; ListAlg2: ICalcObjectsList): Boolean;
Var
IndexCalcAlg1, IndexCalcAlg2: Integer;
CalcBlock, FindedCalcBlock: ICalcObject;
i: Integer;
Begin
For i := 0 To ListAlg1.Count - 1 Do
CalcBlock := ListAlg1.Item(i);
// Search for block by metamodel key
FindedCalcBlock := ListAlg2.FindByMetaModelKey(CalcBlock.MetaModel.Key);
// If block is not found by metamodel key, return False
If FindedCalcBlock = Null Then
Return False;
Else
// If block is found, compare settings
If Not IsSameCalcBlocks(CalcBlock, FindedCalcBlock) Then
Return False;
Else
// Check order of inserting blocks
IndexCalcAlg1 := ListAlg1.IndexOf(CalcBlock);
IndexCalcAlg2 := ListAlg2.IndexOf(FindedCalcBlock);
If IndexCalcAlg1 <> IndexCalcAlg2 Then
Return False;
End If;
End If;
End If;
End For;
// If all block parameters match, return True
Return True;
End Function CalculationChainSeqCompare;
Private Function IsSameCalcBlocks(block1: ICalcOBject; block2: ICalcObject): Boolean;
Begin
If (block1.Key = block2.Key) And (block1.Id = block2.Id) Then
Return True;
Else
Return False;
End If;
End Function IsSameCalcBlocks;
Private Sub AddBlocks(ListAlg1: ICalcObjectsList; ListAlg2: ICalcObjectsList);
Var
CalcBlock: ICalcObject;
i: Integer;
Begin
// Synchronize blocks in the second algorithm relative to the first one
For i := 0 To ListAlg1.Count - 1 Do
CalcBlock := ListAlg1.Item(i);
// If block is missing, add it
If Not ListAlg2.IsContain(CalcBlock) Then
ListAlg2.Add(CalcBlock);
End If;
End For;
// Synchronize blocks in the second algorithm relative to the first one
For i := 0 To ListAlg2.Count - 1 Do
CalcBlock := ListAlg2.Item(i);
// If block is missing, add it
If Not ListAlg1.IsContain(CalcBlock) Then
ListAlg1.Add(CalcBlock);
End If;
End For;
End Sub AddBlocks;
After executing the example, object chains of both calculation algorithms are compared. If chains are different, the corresponding objects will be added to the corresponding calculation algorithm.
See also: