Executing the example requires that the repository contains the Resources object with the OBJ_RES identifier. The file system must contain two icons: C:\Icon_small.ico and C:\Icon_large.ico.
Add links to the system assemblies:
For Fore example: Metabase, Drawing, IO.
For Fore.NET example: Metabase, Drawing, ForeIO, ForeSystem.
Sub UserProc;
Var
Mb: IMetabase;
Obj: IMetabaseObject;
CustomClassExtender: IMetabaseCustomExtender;
CustClasses: IMetabaseCustomClasses;
CustomClass: IMetabaseCustomClass;
Operations: IMetabaseCustomClassOperations;
Operation: IMetabaseCustomClassOperation;
CreateInfo: IMetabaseObjectCreateInfo;
Description: IMetabaseObjectDescriptor;
ImgList, ImgList32: IGxImageList;
Icon: IGxIcon;
CustomObject: IMetabaseCustomObject;
se: IMetabaseSecurity;
AL: IAuditLog;
ALogs: IAuditLogons;
AOperat: IAuditOperations;
i: Integer;
Lic: Object;
Begin
Mb := MetabaseClass.Active;
// Creating a custom class 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);
Obj := Description.Edit;
CustomClassExtender := Obj 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";
// Adding a custom class to the 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";
Obj.Save;
// Creating a custom class object
CreateInfo.ClassId := CustomClass.ClassId;
CreateInfo.Name := "Own class object";
CreateInfo.Permanent := True;
CreateInfo.Parent := Mb.Root;
Description := Mb.CreateObject(CreateInfo);
Obj := Description.Edit;
CustomObject := Obj As IMetabaseCustomObject;
CustomObject.Extender := CustomClassExtender;
CustomObject.CustomClass := CustomClass;
Obj.Save;
// Check access permissions for custom class operation.
Lic := MB.RequestLicense(UiLicenseFeatureType.Adm);
se := Mb.Security;
Description.CheckAndAudit(CustomClass.Key, "Check access permissions for 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("Comment: " + AOperat.Comment);
Debug.WriteLine("--------");
AOperat.Next;
End For;
Lic := Null;
End Sub UserProc;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Drawing;
Imports Prognoz.Platform.Interop.ForeIO;
Imports Prognoz.Platform.Interop.ForeSystem;
…
Public Shared Sub Main(Params: StartParams);
Var
Mb: IMetabase;
Obj: IMetabaseObject;
CustomClassExtender: IMetabaseCustomExtender;
CustClasses: IMetabaseCustomClasses;
CustomClass: IMetabaseCustomClass;
Operations: IMetabaseCustomClassOperations;
Operation: IMetabaseCustomClassOperation;
CreateInfo: IMetabaseObjectCreateInfo;
Description: IMetabaseObjectDescriptor;
ImgList, ImgList32: GxImageList;
Icon: GxIcon;
CustomObject: IMetabaseCustomObject;
se: IMetabaseSecurity;
AL: IAuditLog;
ALogs: IAuditLogons;
AOperat: IAuditOperations;
i: Integer;
Lic: Object;
Begin
Mb := Params.Metabase;
// Creating a custom class container
CreateInfo := Mb.CreateCreateInfo();
CreateInfo.ClassId := MetabaseObjectClass.KE_CLASS_CUSTOM_EXTENDER As Integer;
CreateInfo.Name := "CUSTOM_EXTENDER";
CreateInfo.Permanent := True;
CreateInfo.Parent := Mb.Root;
Description := Mb.CreateObject(CreateInfo);
Obj := Description.Edit();
CustomClassExtender := Obj As IMetabaseCustomExtender;
ImgList := New GxImageList.Create();
ImgList.Height := 16;
Icon := New GxIcon.Create();
Icon.CreateFromFile("C:\Icon_small.ico");
ImgList.AddIcon(Icon);
CustomClassExtender.SmallImages := ImgList;
ImgList32 := New GxImageList.Create();
ImgList32.Height := 32;
Icon := New GxIcon.Create();
Icon.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";
// Adding a custom class to the 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";
Obj.Save();
// Creating a custom class object
CreateInfo.ClassId := CustomClass.ClassId;
CreateInfo.Name := "Own class object";
CreateInfo.Permanent := True;
CreateInfo.Parent := Mb.Root;
Description := Mb.CreateObject(CreateInfo);
Obj := Description.Edit();
CustomObject := Obj As IMetabaseCustomObject;
CustomObject.Extender := CustomClassExtender;
CustomObject.CustomClass := CustomClass;
Obj.Save();
// Check access permissions for custom class operation.
Lic := MB.RequestLicense(UiLicenseFeatureType.lftAdm);
se := Mb.Security;
Description.CheckAndAudit(CustomClass.Key As Integer, "Check access permissions for operation");
Al := se.OpenAuditLog();
ALogs := AL.OpenLogons(False);
AOperat := AL.OpenOperations(ALogs.Session);
For i := 0 To 4 Do
System.Diagnostics.Debug.WriteLine("Object: " + AOperat.ObjectName);
System.Diagnostics.Debug.WriteLine("Operation: " + AOperat.Name);
System.Diagnostics.Debug.WriteLine("Succeeded: " + AOperat.Succeeded.ToString());
System.Diagnostics.Debug.WriteLine("Comment: " + AOperat.Comment);
System.Diagnostics.Debug.WriteLine("--------");
AOperat.Next();
End For;
Lic := Null;
End Sub;
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