Selection schemas are hidden child objects of the dictionary. Each selection schema is an object of the MetabaseObjectClass.KE_CLASS_DIMSELECTIONSCHEMA class. To work with a selection schema, it is necessary to cast the corresponding child object of the dictionary to the IDimSelectionSchema type.
Var
MB: IMetabase;
MDesc: IMetabaseObjectDescriptor;
MDescs: IMetabaseObjectDescriptors;
SelSchema: IDimSelectionSchema;
Begin
MB := MetabaseClass.Active;
MDesc := MB.ItemById("Dim_1");
MDescs := MDesc.Children;
Debug.WriteLine("Selection schemas of dictionary");
For Each MDesc In MDescs Do
If MDesc.ClassId = MetabaseObjectClass.KE_CLASS_DIMSELECTIONSCHEMA Then
Debug.WriteLine("Name: " + MDesc.Name);
SelSchema := MDesc.Bind As IDimSelectionSchema;
Debug.WriteLine("Number of primitives: " + SelSchema.Count.ToString);
End If;
End For;
A selection schema is a set of primitives. Every primitive implements a certain algorithm to select or deselect elements. Two types of primitives: static and dynamic are created for selection schemas. Static primitives contain a certain selection formed on creating primitive. Dynamic primitives implement a certain algorithm that forms the selection when working with dictionary. Final selection schema is obtained after alternate implementation of all the primitives. Any primitive inherits from the IDimSelectionSchemaPrimitive type. The following types of primitives are available for selection schema:
Static primitives.
Select all - selects or deselects all dictionary elements. This primitive inherits from the IDimAllSelectionPrimitive type.
Select listed - selects or deselects the specified dictionary elements. This primitive inherits from the IDimListSelectionPrimitive type.
Select dependent - selects or deselects the specified dictionary elements and their child elements. This primitive inherits from the IDimChildrenSelectionPrimitive type.
Select level - selects or deselects the elements of the selected dictionary level. This primitive inherits from the IDimLevelSelectionPrimitive type.
Dynamic primitives
Always select level - after an element is selected, selects or deselects all elements located on the same level. This primitive inherits from the IDimSelectedSiblingsPrimitive type.
Always select with parents - after an element is selected, selects or deselects all parental elements up to the highest level. This primitive inherits from the IDimSelectedAncestorsPrimitive type.
Always select with dependent - after an element is selected, selects or deselects all its child elements up to the lowest level. This primitive inherits from the IDimSelectedChildrenPrimitive type.
Var
MB: IMetabase;
MDesc: IMetabaseObjectDescriptor;
Dimension: IDimensionModel;
CrInfo: IMetabaseObjectCreateInfo;
Schema: IDimSelectionSchema;
LvlPrimitive: IDimLevelSelectionPrimitive;
Begin
MB := MetabaseClass.Active;
MDesc := MB.ItemById("Dim_1");
Dimension := MDesc.Bind As IDimensionModel;
//Data for creating a selection schema
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassId := MetabaseObjectClass.KE_CLASS_DIMSELECTIONSCHEMA;
CrInfo.Id := "Schema1";
CrInfo.Name := "Selection schema 1";
CrInfo.Parent := MDesc;
/Creating a selection schema with static primitive
Schema := MB.CreateObject(CrInfo).Edit As IDimSelectionSchema;
//Indication of dictionary
Schema.Dimension := Dimension;
//Adding a primitive, selecting elements of level
//Supposed at least one level available in the dictionary
LvlPrimitive := Schema.Add(SelectionPrimitiveType.Level) As IDimLevelSelectionPrimitive;
LvlPrimitive.Included(Dimension.Levels.Item(0)) := True;
//Saving selection schema
(Schema As IMetabaseObject).Save;
//Creating a selection schema with a dynamic primitive
CrInfo.Id := "Schema2";
CrInfo.Name := "Selection schema 2";
Schema := MB.CreateObject(CrInfo).Edit As IDimSelectionSchema;
Schema.Dimension := Dimension;
Schema.Add(SelectionPrimitiveType.SelectedAncestors);
(Schema As IMetabaseObject).Save;
Organization of static primitive selection is similar to working with dictionary selection, and is described in the Work with Dictionary Data: Dictionary Selection section.
See also: