Add(Key: String; Obj: Object);
Add(Key: String; Obj: Object);
Key. Key of the created element.
Obj. Dimensions selection, which will be saved in the created element.
The Add method adds a new element to the collection and saves the passed dimension selection in its metadata.
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.
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.
The requirements and result of the Fore.NET example execution match with those in the Fore example. Use Fore.NET analogs instead of Fore components.
Imports Prognoz.Platform.Forms.NET;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Metabase;
Private Sub button1_Click(sender: System.Object; e: System.EventArgs);
Var
MB: IMetabase;
CustomObj: IMetabaseCustomObject;
Writer: IMetabaseCustomObjectWriter;
WriterSelSet: IMetabaseCustomObjectSelSets;
DimSSFactory: IDimSelectionSetFactory = New DimSelectionSetFactoryClass();
DimSS: IDimSelectionSet;
DimS: IDimSelection;
Begin
MB := Self.Metabase;
CustomObj := MB.ItemById["SelectionStorage"].Edit() As IMetabaseCustomObject;
Writer := CustomObj.CreateWriter();
//Create selection
DimSS := DimSSFactory.CreateDimSelectionSet();
DimS := DimSS.Add(UiDimensionNet1.DimInstance);
UiDimensionNet1.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;
Private Sub button2_Click(sender: System.Object; e: System.EventArgs);
Var
MB: IMetabase;
CustomObj: IMetabaseCustomObject;
Reader: IMetabaseCustomObjectReader;
DimSS: IDimSelectionSet;
Begin
MB := Self.Metabase;
CustomObj := MB.ItemById["SelectionStorage"].Edit() As IMetabaseCustomObject;
Reader := CustomObj.CreateReader();
DimSS := Reader.Selections.FindByKey("DimSelection") As IDimSelectionSet;
UiDimensionNet1.Selection := DimSS.Item[0];
End Sub;
See also: