Executing the example requires that the repository contains a table with the TAB_ELEMENT identifier. ". The table has four fields: Id, Name, Ord and Parent_Id.
Sub UserProc;
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;
//Create attributes
StAttr := StAttrs.Add;
StAttr.DataType := DbDataType.Integer;
StAttr.Id := "Id";
StAttr.Name := "Identifier";
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";
//Sorting by ascending attribute values
Orders := StAttrs.Orders;
Orders.Add(StAttrs.Name, False);
Orders.Add(StAttrs.Order, False);
//Create a recursive block
StDimBlock := StDim.Blocks.Add(DimBlockType.Recursive);
//Set up block
//Primary index of block by the Identifier attribute
BlockAttr := StDimBlock.Indexes.PrimaryIndex.Attributes;
BlockAttr.Add(StAttrs.Id);
//Bind 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 upper recursion level
StRecBlock.StartWith.AsString := "TAB_ELEMENT.PARENT_ID=0";
//Link by primary index
StRecBlock.ConnectByIndex := StDimBlock.Indexes.PrimaryIndex;
//Condition of link for the first attribute
StRecBlock.ConnectBy(BlockAttr.Item(0)).AsString := "TAB_ELEMENT.PARENT_ID";
//Two levels for dictionary
Levels := StDim.Levels;
Levels.Add.Name := "First level";
Levels.Add.Name := "Second level";
(StDim As IMetabaseObject).Save;
End Sub UserProc;
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: