Creating a Proper Class Object

Executing the example requires that the repository contains a resource with the RESOURCE identifier. The file system must contain two icons: C:\Icon_small.ico and C:\Icon_large.ico.

Add links to the Drawing, IO, and Metabase system assemblies.

Sub UserProc;
Var
    Mb: IMetabase;
    Type: MetabaseSpecialObject;
    Object: IMetabaseObject;
    CustomClassExtender: IMetabaseCustomExtender;
    CustomClasses: IMetabaseCustomClasses;
    CustomClass: IMetabaseCustomClass;
    CustomObject: IMetabaseCustomObject;
    Operations: IMetabaseCustomClassOperations;
    Operation: IMetabaseCustomClassOperation;
    CreateInfo: IMetabaseObjectCreateInfo;
    Description: IMetabaseObjectDescriptor;
    ImgList, ImgList32: IGxImageList;
    Icon: IGxIcon;
Begin
    // Get the current repository
    Mb := MetabaseClass.Active;
    // Get custom class container
    Type := MetabaseSpecialObject.CustomExtender;
    CustomClassExtender := Mb.SpecialObject(Type).Edit As IMetabaseCustomExtender;
    // Set resource for container
    CustomClassExtender.Resource := Mb.ItemById("RESOURCE").Bind As IResourceObject;
    CustomClassExtender.NameResource := "ID_CUSTOM_EXTENDER";
    // Load large and small icons to the collection
    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;
    // Create a custom class in container
    CustomClasses := CustomClassExtender.Classes;
    CustomClass := CustomClasses.Add;
    // Set custom  class parameters
    CustomClass.Name := "Custom class";
    CustomClass.Description := "Container class";
    CustomClass.IsContainer := True;
    CustomClass.LargeImageIndex := 0;
    CustomClass.SmallImageIndex := 0;
    CustomClass.ImplementationURL := "https://site/CoolScript.js";
    // Create an operation for custom class
    Operations := CustomClass.Operations;
    Operation := Operations.Add(0);
    Operation.Name := "New method";
    // Save changes of custom class container
    (CustomClassExtender As IMetabaseObject).Save;
    // Create an custom class object in repository root
    CreateInfo := Mb.CreateCreateInfo;
    CreateInfo.ClassId := CustomClass.ClassId;
    CreateInfo.Name := "Proper class object";
    CreateInfo.Permanent := True;
    CreateInfo.Parent := Mb.Root;
    Description := Mb.CreateObject(CreateInfo);
    Object := Description.Edit;
    CustomObject := Object As IMetabaseCustomObject;
    CustomObject.Extender := CustomClassExtender;
    CustomObject.CustomClass := CustomClass;
    // Save changes of custom class object
    Object.Save;
End Sub UserProc;

After executing the example:

See also:

Examples | IMetabaseCustomExtender | IMetabaseCustomClass | IMetabaseCustomClassOperation | IMetabaseCustomObject