Hierarchy: IDimHierarchyInstance;
The Hierarchy property determines data of alternative hierarchy of dictionary elements.
Executing the example requires that the repository contains dictionaries with the TB_BASE and TB_ALT identifiers. The TB_BASE dictionary is used as a basic dictionary, while the TB_ALT dictionary is to be used as an alternative hierarchy dictionary. There should also be a form containing a button with the Button1 identifier, the DimensionTree component with the DimensionTree1 identifier, and the UiDimension component with the UiDimension1 identifier, which is a data source for the DimensionTree1 component. The UiDimension component should use the TB_BASE dictionary as its data source. This example is executed on clicking the button.
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
Mb: IMetabase;
OriginalModelObj: IMetabaseObject;
OriginalModel: IDimensionModel;
AlternateModel: IDimensionModel;
Hierarchies: IDimHierarchies;
Alt_Hierarchy: IDimHierarchy;
i: Integer;
Origin_Attributes: IDimAttributes;
Alt_Attributes: IDimAttributes;
Origin_Attr: IDimAttribute;
Alt_Attr: IDimAttribute;
dimInstance: IDimInstance;
Hs_Instance: IDimHierarchiesInstance;
H_Inst: IDimHierarchyInstance;
dimSel: IDimSelection;
Begin
Mb := MetabaseClass.Active;
OriginalModelObj := Mb.ItemById("TB_BASE").Edit;
OriginalModel := OriginalModelObj As IDimensionModel;
AlternateModel := Mb.ItemById("TB_ALT").Bind As IDimensionModel;
Hierarchies := OriginalModel.Hierarchies;
Hierarchies.Clear;
// Determine index, containing keys of elements for alternative hierarchy
Hierarchies.OriginalIndex := OriginalModel.Indexes.PrimaryIndex;
// Add source alternative hierarchy
Alt_Hierarchy := Hierarchies.Add(AlternateModel);
// Determine index containing keys for comparing elements of main and alternative dictionary
Alt_Hierarchy.SourceIndex := AlternateModel.Indexes.PrimaryIndex;
Origin_Attributes := OriginalModel.Attributes;
Alt_Attributes := AlternateModel.Attributes;
// Link attributes of original dimension with attributes from source of alternative hierarchy
For i := 0 To Origin_Attributes.Count - 1 Do
Origin_Attr := Origin_Attributes.Item(i);
Alt_Attr := Alt_Attributes.Item(i);
Alt_Hierarchy.SourceAttribute(Origin_Attr) := Alt_Attr;
End For;
OriginalModelObj.Save;
// Change main hierarchy for alternative
dimInstance := OriginalModelObj.Open(Null) As IDimInstance;
Hs_Instance := dimInstance.Hierarchies;
If Hs_Instance.Count > 0 Then
H_Inst := Hs_Instance.Item(0);
dimSel := DimensionTree1.Selection;
dimSel.Hierarchy := H_Inst;
End If;
End Sub Button1OnClick;
After executing the example alternative hierarchy is added and set for the basic dictionary.
See also: