Executing the example requires that the repository contains a unit with the UserDimMod identifier containing a macro for creating an element tree of calculated dictionary. Assume that macro contains the following code:
Sub UserProc;
Var
MB: IMetabase;
MObj: IMetabaseObject;
Params: IMetabaseObjectParams;
Param: IMetabaseObjectParam;
CrInfo: IMetabaseObjectCreateInfo;
UserDim: IUserDimension;
Attrs: IUserDimAttributes;
Attr: IUserDimAttribute;
Orders: IUserDimOrders;
Block: IUserDimBlock;
BlockAttr: IUserDimIndexAttributes;
Levels: IUserDimLevels;
Begin
MB := MetabaseClass.Active;
CrInfo := MB.CreateCreateInfo;
CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_USERDIM;
CrInfo.Id := "NewUserDim";
CrInfo.Name := "New calculated dictionary";
CrInfo.Parent := MB.Root;
MObj := MB.CreateObject(CrInfo).Edit;
// Dictionary parameters
Params := MObj.Params;
Param := Params.Add;
Param.Id := "i1";
Param.Name := "Number of main elements";
Param.DataType := DbDataType.Integer;
Param := Params.Add;
Param.Id := "k1";
Param.Name := "Number of child elements";
Param.DataType := DbDataType.Integer;
UserDim := MObj As IUserDimension;
Attrs := UserDim.Attributes;
// Create attributes
Attr := Attrs.Add;
Attr.DataType := DbDataType.Integer;
Attr.Id := "Id";
Attr.Name := "Identifier";
Attrs.Id := Attr;
Attr := Attrs.Add;
Attr.DataType := DbDataType.String;
Attr.Id := "Name";
Attr.Name := "Name";
Attrs.Name := Attr;
Attr := Attrs.Add;
Attr.DataType := DbDataType.Integer;
Attr.Id := "Order";
Attr.Name := "Order";
Attrs.Order := Attr;
// Sort by attributes
Orders := Attrs.Orders;
Orders.Add(Attrs.Name, False);
Orders.Add(Attrs.Order, False);
// Single block
Block := UserDim.Blocks.Add;
// Primary index of block by the Identifier attribute
BlockAttr := Block.Indexes.PrimaryIndex.Attributes;
BlockAttr.Add(Attrs.Id);
// Two levels for dictionary
Levels := UserDim.Levels;
Levels.Add.Name := "First level";
Levels.Add.Name := "Second level";
// Set unit and macro
UserDim.ForeModule := MB.ItemById("UserDimMod").Bind As IModule;
UserDim.ForeSub := "UserMacro";
(UserDim As IMetabaseObject).Save;
End Sub UserProc;
After executing the example the repository root contains a calculated dictionary. The dictionary contains three attributes and one block, sorting order of elements is set. The primary block index contains the ID attribute. Two dictionary levels are created, module and macro that creates element tree are set.
Two parameters are also created for the dictionary. If the above mentioned macro is used to create an element tree, these parameters are used to set the number of root elements and the number of child elements for every root one, respectively.
See also: