IMetabaseCustomObjectSelSets.Add

Syntax

Add(Key: String; Obj: Object);

Parameters

Key. Key of the created element.

Obj. Dimensions selection, which will be saved in the created element.

Description

The Add method adds a new element to the collection and saves the passed dimension selection in its metadata.

Comments

It is necessary to specify a unique key of the created element as value of the Key parameter. If the collection has already contain the element with the specified key, exception is generated. As a value of the Obj parameter, it is necessary to pass the dimension selection described by the IDimSelectionSet interface.

Example

Executing the example requires a form with two buttons Button1 and Button2, the UiDimension component named UiDimension1 and any components used to change selection of the dictionary linked to UiDimension1. The repository should also contains a custom class object with the SelectionStorage identifier. Add links to the Dimension, Metabase system assemblies.

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    MB: IMetabase;
    CustomObj: IMetabaseCustomObject;
    Writer: IMetabaseCustomObjectWriter;
    WriterSelSet: IMetabaseCustomObjectSelSets;
    DimSSFactory: IDimSelectionSetFactory;
    DimSS: IDimSelectionSet;
    DimS: IDimSelection;
Begin
    MB := MetabaseClass.Active;
    CustomObj := MB.ItemById("SelectionStorage").Edit As IMetabaseCustomObject;
    Writer := CustomObj.CreateWriter;
    //Create selection
    DimSSFactory := New DimSelectionSetFactory.Create;
    DimSS := DimSSFactory.CreateDimSelectionSet;
    DimS := DimSS.Add(UiDimension1.DimInstance);
    UiDimension1.Selection.CopyTo(DimS, True);
    //Write selection to custom class object
    WriterSelSet := Writer.Selections;
    If WriterSelSet.FindByKey("DimSelection") <> Null Then
        WriterSelSet.RemoveByKey("DimSelection");
    End If;
    WriterSelSet.Add("DimSelection", DimSS);
    //Save changes
    Writer.Save;
    (CustomObj As IMetabaseObject).Save;
End Sub Button1OnClick;

Sub Button2OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    MB: IMetabase;
    CustomObj: IMetabaseCustomObject;
    Reader: IMetabaseCustomObjectReader;
    DimSS: IDimSelectionSet;
Begin
    MB := MetabaseClass.Active;
    CustomObj := MB.ItemById("SelectionStorage").Edit As IMetabaseCustomObject;
    Reader := CustomObj.CreateReader;
    DimSS := Reader.Selections.FindByKey("DimSelection"As IDimSelectionSet;
    UiDimension1.Selection := DimSS.Item(0);
End Sub Button2OnClick;

Clicking the first button saves selection of the dictionary linked to the UiDimension1 component into the custom class object. Clicking the second button restores the selection from the specified custom class object and installs in the UiDimension1 component.

See also:

IMetabaseCustomObjectSelSets