Getting and Working with Object Data

After creating and setting up objects, fill them with data or get their current data. To get object data, it should be opened, use the IMetabaseObjectDescriptor.Open or IMetabaseObjectDescriptor.OpenWithParam method for it. The methods returns the IMetabaseObjectInstance interface that is common for all opened objects.

When opening various objects, the data term can refer to various entities:

The interfaces that are developed for work with data of various repository objects are described in various assemblies, for example:

For details see the list of available assemblies and their contents.

See the examples of table, dictionary and cube data viewing:

Sub TableData;
Var
    Mb: IMetabase;
    TableInst: IDatasetInstance;
    Fields: IDatasetInstanceFields;
    Field1, Field2, Field3: IDatasetInstanceField;
Begin
    Mb := MetabaseClass.Active;
    // Open table and cast to the interface that is used to work with data
    TableInst := Mb.ItemById("TABLE").Open(NullAs IDatasetInstance;
    // Get fields
    Fields := TableInst.Fields;
    Field1 := Fields.FindById("ID");
    Field2 := Fields.FindById("NAME");
    Field3 := Fields.FindById("VALUE");
    // Go through all records and view field values
    While Not TableInst.Eof Do
        Debug.Write("Identifier: " + Field1.Value);
        Debug.Write(". Name: " + Field2.Value);
        Debug.WriteLine(". Value: " + Field3.Value);
        TableInst.Next;
    End While;
    TableInst.Close;
End Sub TableData;

Sub DictionaryData;
Var
    Mb: IMetabase;
    DictInst: IDimInstance;
    Elements: IDimElements;
    Attribute: IDimAttributeInstance;
    i: Integer;
Begin
    Mb := MetabaseClass.Active;
    // Open dictionary and cast to the interface that is used to work with data
    DictInst := Mb.ItemById("DICTIONARY").Open(NullAs IDimInstance;
    // Get list of elements
    Elements := DictInst.Elements;
    // Get the VALUE attribute
    Attribute := DictInst.Attributes.FindById("VALUE");
    // View attribute values for each dictionary element
    For i := 0 To Elements.Count - 1 Do
        Debug.Write("Identifier: " + Elements.Id(i));
        Debug.Write(". Name: " + Elements.Name(i));
        Debug.WriteLine(". Value: " + Elements.AttributeValueO(i, Attribute));
    End For;
End Sub DictionaryData;

Sub CubeData;
Var
    Mb: IMetabase;
    CubeInst: ICubeInstance;
    Destination: ICubeInstanceDestination;
    SelSet: IDimSelectionSet;
    Matr: IMatrix;
    Iter: IMatrixIterator;
Begin
    Mb := MetabaseClass.Active;
    // Open cube and cast to the interface that is used to work with data
    CubeInst := Mb.ItemById("STANDART_CUBE").Open(NullAs ICubeInstance;
    Destination := CubeInst.Destinations.DefaultDestination;
    // Create and form the selection, by which value matrix will be calculated
    SelSet := Destination.CreateDimSelectionSet;
    SelSet.FindById("COUNTRY").SelectElement(0False);
    SelSet.FindById("CALENDAR").SelectAll;
    // Calculate value matrix
    Matr := Destination.Execute(SelSet);
    // Iterator for going through all obtained values
    Iter := Matr.CreateIterator;
    Iter.Move(IteratorDirection.First);
    While Iter.Valid Do
        Debug.Write(Iter.Value + " ");
        Iter.Move(IteratorDirection.Next);
    End While;
End Sub CubeData;

See also:

Developing User Application