Creating a Proper Class Object

Executing the example requires that the repository contains a resources object with the OBJ_RES identifier. The file system must contain two icons: C:&Icon\small.ico and C:_Icon&large.ico.

Sub Main;

Var

Mb: IMetabase;

Object: IMetabaseObject;

CustomClassExtender: IMetabaseCustomExtender;

CustClasses: IMetabaseCustomClasses;

CustomClass: IMetabaseCustomClass;

Operations: IMetabaseCustomClassOperations;

Operation: IMetabaseCustomClassOperation;

CreateInfo: IMetabaseObjectCreateInfo;

Description: IMetabaseObjectDescriptor;

ImgList: IGxImageList;

ImgList32: IGxImageList;

Icon: IGxIcon;

CustomObject: IMetabaseCustomObject;

se: IMetabaseSecurity;

AL: IAuditLog;

ALogs: IAuditLogons;

AOperat: IAuditOperations;

i: Integer;

Begin

Mb := MetabaseClass.Active;

// Creation of the custom classes container

CreateInfo := Mb.CreateCreateInfo;

CreateInfo.ClassId := MetabaseObjectClass.KE_CLASS_CUSTOM_EXTENDER;

CreateInfo.Name := "CUSTOM_EXTENDER";

CreateInfo.Permanent := True;

CreateInfo.Parent := Mb.Root;

Description := Mb.CreateObject(CreateInfo);

Object := Description.Edit;

CustomClassExtender := Object As IMetabaseCustomExtender;

ImgList := New GxImageList.Create;

ImgList.Height := 16;

Icon := New GxIcon.CreateFromFile("C:\Icon_small.ico");

ImgList.AddIcon(Icon);

CustomClassExtender.SmallImages := ImgList;

ImgList32 := New GxImageList.Create;

ImgList32.Height := 32;

Icon := New GxIcon.CreateFromFile("C:\Icon_large.ico");

ImgList32.AddIcon(Icon);

CustomClassExtender.LargeImages := ImgList32;

CustomClassExtender.IsShared := True;

CustomClassExtender.Resource := Mb.ItemById("OBJ_RES").Bind As IResourceObject;

CustomClassExtender.NameResource := "ID_CUSTOM_EXTENDER";

 

// Add custom class into a container

CustClasses := CustomClassExtender.Classes;

CustomClass := CustClasses.Add;

CustomClass.Description := "Own class";

CustomClass.Id := "MY_CLASS";

CustomClass.Name := "My_Class";

CustomClass.ImageIndex := 0;

Operations := CustomClass.Operations;

Operation := Operations.Add(0);

Operation.Name := "New method";

Object.Save;

 

// Creation of the custom class object

CreateInfo.ClassId := CustomClass.ClassId;

CreateInfo.Name := "An object of its own class";

CreateInfo.Permanent := True;

CreateInfo.Parent := Mb.Root;

Description := Mb.CreateObject(CreateInfo);

Object := Description.Edit;

CustomObject := Object As IMetabaseCustomObject;

CustomObject.Extender := CustomClassExtender;

CustomObject.CustomClass := CustomClass;

Object.Save;

 

// Check access permissions to an operation of a custom class.

se := Mb.Security;

Description.CheckAndAudit(CustomClass.Key, "Check access permissions to an operation");

Al := se.OpenAuditLog;

ALogs := AL.OpenLogons(False);

AOperat := AL.OpenOperations(ALogs.Session);

For i := 0 To 4 Do

Debug.WriteLine("Object: " + AOperat.ObjectName);

Debug.WriteLine("Operation: " + AOperat.Name);

Debug.WriteLine("Succeeded: " + AOperat.Succeeded.ToString);

Debug.WriteLine("Comments: " + AOperat.Comment);

Debug.WriteLine("--------");

AOperat.Next;

End For;

End Sub Main;

After executing this example a container of a custom class that contains one class: "My_Class" is created. An identifier of the string resource ID_CUSTOM_EXTENDER from the OBJ_RES resources will be determined for a container. One operation will be defined for a class. An object of a class "My_Class" will be created in repository. The C:&Icon\large.ico file is a source of a large icon, the C:_Icon&small.ico file - of a small icon. Access permissions on a class operation will be checked for an object, results will be written in access protocol. Five last records of a protocol will be output into console window.

See also:

Examples | IMetabaseCustomExtender | IMetabaseCustomClass | IMetabaseCustomClassOperation | IMetabaseCustomObject