Groups of elements are hidden child objects of the dictionary. Every group of elements is object of the class MetabaseObjectClass.KE_CLASS_DIMELEMENTGROUP. To work with a group of elements, cast the appropriate child object of the dictionary to the IDimElementGroup type.
Var
MB: IMetabase;
MDesc: IMetabaseObjectDescriptor;
MDescs: IMetabaseObjectDescriptors;
ElemGroup: IDimElementGroup;
Begin
MB := MetabaseClass.Active;
MDesc := MB.ItemById("Dim_1");
MDescs := MDesc.Children;
Debug.WriteLine("Groups of elements of the dictionary");
For Each MDesc In MDescs Do
If MDesc.ClassId = MetabaseObjectClass.KE_CLASS_DIMELEMENTGROUP Then
Debug.WriteLine("Name: " + MDesc.Name);
ElemGroup := MDesc.Bind As IDimElementGroup;
Debug.WriteLine("Number of primitives: " + ElemGroup.Count.ToString);
End If;
End For;
To create a selection group, create a repository object of the MetabaseObjectClass.KE_CLASS_DIMELEMENTGROUP class, and specify a repository dictionary as a parent of this object. After the created object is opened to edit and cast to the IDimElementGroup interface, the collection of primitives can be changed. The group of elements is a set of primitives united by method indicated in the UnionType property. Every primitive implements a certain algorithm for elements selection. Any primitive inherits from the IDimElementGroupPrimitive type. The following types of primitives are available:
Elements of list - Group contains elements selected in primitive. This primitive inherits from the IDimListGroupPrimitive type.
Level elements - group contains elements of the selected dictionary level. This primitive inherits from the IDimLevelsGroupPrimitive type.
Elements by common owner - a group contains child elements of elements selected in the primitive. This primitive inherits from the IDimChildrenGroupPrimitive type.
Elements by common owner with owner - a group contains elements selected in the primitive including all their child elements. This primitive inherits from the IDimChildrenWithParentGroupPrimitive type.
Var
MB: IMetabase;
MDesc: IMetabaseObjectDescriptor;
Dimension: IDimensionModel;
CrInfo: IMetabaseObjectCreateInfo;
Group: IDimElementGroup;
LvlPrimitive: IDimLevelsGroupPrimitive;
ChildWhitePrimitive: IDimChildrenWithParentGroupPrimitive;
Begin
MB := MetabaseClass.Active;
MDesc := MB.ItemById("Dim_1");
Dimension := MDesc.Bind As IDimensionModel;
//Data for creating a group of elements
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassId := MetabaseObjectClass.KE_CLASS_DIMELEMENTGROUP;
CrInfo.Id := "Group1";
CrInfo.Name := "Group of elements 1";
CrInfo.Parent := MDesc;
//Creating a group of elements
Group := MB.CreateObject(CrInfo).Edit As IDimElementGroup;
//Indication of dictionary
Group.Dimension := Dimension;
//Method of cooperation of primitives
Group.UnionType := UnionGroupType.Intersection;
//Creating a primitive that returns elements of levels
LvlPrimitive := Group.AddPrimitive(SelectionGroupType.Levels) As IDimLevelsGroupPrimitive;
LvlPrimitive.AddLevel(Dimension.Levels.Item("LEVEL2"));
//Creating a primitive that returns child elements with parent
ChildWhitePrimitive := Group.AddPrimitive(SelectionGroupType.ChildrenWithParent) As IDimChildrenWithParentGroupPrimitive;
ChildWhitePrimitive.Selection.SelectElement(0, False);
(Group As IMetabaseObject).Save;
The created group of elements can be used later to set up components, displaying a tree of dictionary elements, in regular reports to set up slices of data sources, and in other blocks of the platform, that provide working with groups of dictionary elements. It is also possible to use the selection corresponding to group elements and available in the Selection property.
See also: