To get dictionary data it is required to open the appropriate repository object and cast the obtained instance to the IDimInstance interface. IDimInstance is the main interface that gives opportunities to work with dictionary elements, values of selected attributes, indexes, dictionary levels and dictionary selection.
Var
MB: IMetabase;
DimInst: IDimInstance;
Begin
MB := MetabaseClass.Active;
DimInst := MB.ItemById("Dim_1").Open(Null) As IDimInstance;
The IDimElements interface is used to work with the collection of dictionary elements. The Elements property can be used to get the collection of elements. The collection includes all the elements the user has read access to, without separation into levels or blocks. Collection elements include end-to-end indexation from 0 to Count -1. With end-to-end index the user can get all its parameters:
Values of all attributes by this element.
Parameters of level, block, index, to which the element belongs.
Var
MB: IMetabase;
DimInst: IDimInstance;
Elements: IDimElements;
Elem: Integer;
Begin
MB := MetabaseClass.Active;
DimInst := MB.ItemById("Dim_1").Open(Null) As IDimInstance;
Elements := DimInst.Elements;
For Elem := 0 To Elements.Count - 1 Do
Debug.WriteLine("ID: " + Elements.Id(Elem) + " ;Name: " + Elements.Name(Elem));
End For;
This code displays values of the ID and Name attributes for all the dictionary elements.
Various methods of the IDimElements interface are used to work with elements, united by some property (elements of the same level, elements of the same block):
Blocks - elements distributed in dictionary blocks.
Levels - elements distributed in dictionary levels.
RootElements - root elements of the dictionary.
On working with elements integrated by any property, this method does not work with collection, it works with array of elements. The IDimElementArray interface is used to work with elements array. Depending on which property combines the elements, different properties are used to get array:
IDimBlockInstance.Elements - elements of dictionary block.
IDimLevelInstance.Elements - elements of dictionary level.
Indexation of elements in array can differ from end-to-end indexation of elements in dictionary. The Element property is used to get conformity.
Var
MB: IMetabase;
DimInst: IDimInstance;
LvlInst: IDimLevelInstance;
Elements: IDimElements;
ElementArr: IDimElementArray;
i, Elem: Integer;
Begin
MB := MetabaseClass.Active;
DimInst := MB.ItemById("Dim_1").Open(Null) As IDimInstance;
LvlInst := DimInst.Levels.Item("LEVEL1");
//Collection of all dictionary elements
Elements := DimInst.Elements;
//Array of elements of the first level
ElementArr := LvlInst.Elements;
For i := 0 To ElementArr.Count - 1 Do
//Receiving end-to-end index of dictionary element
Elem := ElementArr.Element(i);
Debug.WriteLine("ID: " + Elements.Id(Elem) + " ;Name: " + Elements.Name(Elem));
End For;
This code generates the array of elements located on the specified dictionary level. Values of the ID and Name attributes are displayed in the development environment console for all these elements.
See also: