Working with MDM Dictionary Data

The user works with MDM dictionary data using properties and methods available in the IRdsDictionaryInstance interface.

To access data, it is necessary to open an MDM dictionary and cast it to the IRdsDictionaryInstance interface:

Sub UserProc;
Var
    MB: IMetabase;
    Dict: IRdsDictionary;
    DictInst: IRdsDictionaryInstance;
Begin
    MB := MetabaseClass.Active;
    Dict := MB.ItemById("Dict_1").Bind As IRdsDictionary;
    DictInst := Dict.Open(NullAs IRdsDictionaryInstance;
End Sub UserProc;

Cast the opened MDM dictionary to the IDimInstance interface to use functions of search by the values of element attributes and to work with an iterator, and so on.

Sub UserProc;
Var
    MB: IMetabase;
    DictInst: IRdsDictionaryInstance;
    Inst: IDimInstance;
    Elems: IDimElements;
    ElemArr: IDimElementArray;
    Iter: IDimIterator;
Begin
    MB := MetabaseClass.Active;
    DictInst := MB.ItemById("Dict_1").Open(NullAs IRdsDictionaryInstance;
    Inst := DictInst As IDimInstance;
    Elems := Inst.Elements;
    ElemArr := Inst.RootElements;
    Iter := ElemArr.Iterator;
    While Iter.Next Do
        Debug.WriteLine(Elems.Name(Iter.Element));
    End While;
End Sub UserProc;

After executing the example names of all MDM dictionary root elements are displayed in the development environment console. Iterator of standard dictionaries is used to work with elements.

NOTE. Remember that cached data is used when directly casting to the IDimInstance interface. Use the CreateDimInstance method if it is necessary to get a set of data based on the actual set of elements (for example, data of elements after elements collection is changed during form execution).

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    DictInst: IRdsDictionaryInstance;
    Inst: IDimInstance;
    Elems: IDimElements;
    ElemArr: IDimElementArray;
    Iter: IDimIterator;
Begin
    DictInst := RdsDictionaryBox1.Source.Instance;
    Inst := DictInst.CreateDimInstance;
    Elems := Inst.Elements;
    ElemArr := Inst.RootElements;
    Iter := ElemArr.Iterator;
    While Iter.Next Do
        Debug.WriteLine(Elems.Name(Iter.Element));
    End While;
End Sub Button1OnClick;

After executing the example names of all root elements of the MDM dictionary displayed in the RdsDictionaryBox1 component are displayed in the development environment console. Iterator of standard dictionaries is used to work with elements.

See also:

Examples