Creating Calculated Dictionary

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:

UserMacro procedure

Sub Main;

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;

//Creating attributes

Attr := Attrs.Add;

Attr.DataType := DbDataType.Integer;

Attr.Id := "Id";

Attr.Name := ID;

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;

//Sorting by attributes

Orders := Attrs.Orders;

Orders.Add(Attrs.Name, False);

Orders.Add(Attrs.Order, False);

//One block

Block := UserDim.Blocks.Add;

//Primary block index by the ID attribute

BlockAttr := Block.Indexes.PrimaryIndex.Attributes;

BlockAttr.Add(Attrs.Id);

//Two levels for dictionary

Levels := UserDim.Levels;

Levels.Add.Name := The first level;

Levels.Add.Name := The second level;

//Setting module and macro

UserDim.ForeModule := MB.ItemById("UserDimMod").Bind As IModule;

UserDim.ForeSub := "UserMacro";

(UserDim As IMetabaseObject).Save;

End Sub Main;

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:

Examples