Executing the example requires that the repository contains a dictionary with the TAB_ELEMENT identifier. ". The table has four fields: Id, Name, Ord and Parent_Id.
Sub Main;
Var
MB: IMetabase;
CrInfo: IMetabaseObjectCreateInfo;
StDim: IStandardDimension;
StAttrs: IStandardDimAttributes;
Orders: IStdDimOrders;
BlockAttr: IStandardDimIndexAttributes;
StAttr: IStandardDimAttribute;
StDimBlock: IStandardDimBlock;
StRecBlock: IStandardDimRecursiveBlock;
Levels: IStandardDimLevels;
Begin
MB := MetabaseClass.Active;
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_STDDIM;
CrInfo.Id := "NewTabDim";
CrInfo.Name := New table dictionary;
CrInfo.Parent := MB.Root;
StDim := MB.CreateObject(CrInfo).Edit As IStandardDimension;
StAttrs := StDim.Attributes;
//Creating attributes
StAttr := StAttrs.Add;
StAttr.DataType := DbDataType.Integer;
StAttr.Id := "Id";
StAttr.Name := ID;
StAttrs.Id := StAttr;
StAttr := StAttrs.Add;
StAttr.DataType := DbDataType.String;
StAttr.Id := "Name";
StAttr.Name := Name;
StAttrs.Name := StAttr;
StAttr := StAttrs.Add;
StAttr.DataType := DbDataType.Integer;
StAttr.Id := "Order";
StAttr.Name := Order;
StAttrs.Order := StAttr;
StAttr := StAttrs.Add;
StAttr.DataType := DbDataType.Integer;
StAttr.Id := "Parent";
StAttr.Name := Parent;
//Ascending sorting of attribute values
Orders := StAttrs.Orders;
Orders.Add(StAttrs.Name, False);
Orders.Add(StAttrs.Order, False);
//Creating recursive block
StDimBlock := StDim.Blocks.Add(DimBlockType.Recursive);
//Setting up block
//Primary block index by the ID attribute
BlockAttr := StDimBlock.Indexes.PrimaryIndex.Attributes;
BlockAttr.Add(StAttrs.Id);
//Binding block attributes to fields of the TAB_ELEMENT table
StDimBlock.Dataset := MB.ItemById("TAB_ELEMENT").Bind As IDatasetModel;
StDimBlock.Binding(StAttrs.Id).AsString := "TAB_ELEMENT.ID";
StDimBlock.Binding(StAttrs.Name).AsString := "TAB_ELEMENT.NAME";
StDimBlock.Binding(StAttrs.Order).AsString := "TAB_ELEMENT.ORD";
StDimBlock.Binding(StAttr).AsString := "TAB_ELEMENT.PARENT_ID";
//Recursion adjustment
StRecBlock := StDimBlock As IStandardDimRecursiveBlock;
//Conditions for the upper level of recursion
StRecBlock.StartWith.AsString := "TAB_ELEMENT.PARENT_ID=0";
//Connection by the primary index
StRecBlock.ConnectByIndex := StDimBlock.Indexes.PrimaryIndex;
//Connection condition for the first attribute
StRecBlock.ConnectBy(BlockAttr.Item(0)).AsString := "TAB_ELEMENT.PARENT_ID";
//Two levels for dictionary
Levels := StDim.Levels;
Levels.Add.Name := The first level.
Levels.Add.Name := The second level.
(StDim As IMetabaseObject).Save;
End Sub Main;
After executing the example the repository root contains a table dictionary. The dictionary contains four attributes, one recursive block. Sorting by attributes is set. Bindings of table fields to dictionary attributes and recursion are set. The dictionary also contains two levels for setting up further aggregation.
See also: