In this article:
Open Parameterized Dictionaries
Obtaining Values of Specified Attributes for Selected Dictionary Elements
Obtaining Element Index Based on the Specified Value of its Attribute
Article number: KB000018
Related blocks:
The DimensionTree and DimensionCombo components are used to display data of a dictionary. The DimensionTree displays data as a tree and the DimensionCombo displays data as the drop-down list. The UiDimension component is used as the data source for these components.
Methods of working with dictionaries in the DimensionTree and DimensionCombo components are described below.
The UiMetabaseObjectParams component is used to control values of parameters of repository objects. When working with the UiDimension , you need to configure it to a parameterized dictionary. Do the following:
Add the required parameterized dimension to UiDimension.
Specify the added dictionary in the UiObject property of the UiMetabaseObjectParams component.
Add components that are to control dictionary parameter values.
Bind added components to controlled parameters in the UiMetabaseObjectParams component.
To apply parameters while the form is working you need to refresh the dictionary:
UiDimension1.Active := False;
UiDimension1.Active := True;
There is a custom form containing the following components: Button (identifier Button1), Memo (identifier Memo1), DimensionTree (identifier DimensionTree1) and the UiDimension component used as the data source for DimensionTree.
This example describes obtaining values of the NAME attribute for the dictionary elements selected in the DimensionTree1 component loaded to UiDimension. This example is executed on clicking the Button1.
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
DimInstance: IDimInstance;
SelectedElements: IDimElementArray; //collection of selected elements
Attribute: IDimAttributeInstance; //attribute, value of which must be obtained
ElementIndex, ElementCount: Integer;
DimensionElement: Integer;
Begin
DimInstance := DimensionTree1.Dimension.DimInstance;
Attribute := DimInstance.Attributes.FindById("NAME");
SelectedElements := DimensionTree1.Selection.SelectedElementArray(NULL);
ElementCount := SelectedElements.Count - 1;
For ElementIndex := 0 To ElementCount Do
DimensionElement := SelectedElements.Element(ElementIndex);
Memo1.Lines.Add(Attribute.Value(DimensionElement) As String);
End For;
End Sub Button1OnClick;
After executing this example value of the NAME attribute for each of the selected elements is added to the Memo1 component.
There is a custom form containing the following components: Button (identifier Button1), Memo (identifier Memo1), DimensionTree (identifier DimensionTree1) and the UiDimension component used as the data source for DimensionTree.
This example describes obtaining index of the dictionary element displayed in the DimensionTree1 component. Element index is to be obtained based on the value of the specified attribute. This example is executed on clicking the Button1.
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
DimInstance: IDimInstance;
Attributes: IDimAttributesInstance;
DimensionElement, //index of found dictionary element
AtIndex: Integer; //index of attribute, by which the search is performed
AtValue: Variant; //attribute value, by which the search is performed
Begin
AtIndex := 1;
AtValue := "Fifth element";
DimInstance := DimensionTree1.Dimension.DimInstance;
Attributes := DimInstance.Attributes;
DimensionElement := Attributes.Item(AtIndex).LookupValue(AtValue);
Memo1.Lines.Add(DimensionElement.ToString);
End Sub Button1OnClick;
After executing this example the Memo1 component contains index of the element which has the value of the attribute with index 1 equal to "Fifth element".
Instead the Item(AtIndex) it is available to use the FindById("NAME") to search for the dictionary element index by the specified attribute with the NAME identifier.
See also:
DimensionTree | DimensionCombo | UiDimension | UiMetabaseObjectParams