In this article:

Creating a Shortcut

Creating a Shortcut for an Object from Other Repository

Editing Objects via Shortcut

Working with Shortcut

The platform repository implements various object classes that have specific purpose and execute specific functions. The repository has also such a class of objects as Shortcut. Shortcut is a link to an existing object of some class. The shortcut contains properties of the object, to which it refers. On viewing or editing a shortcut the appropriate platform tool or wizard opens that is used to edit properties of the corresponding object.

On working via the Fore language the following properties can be used to check correspondence between object and shortcut:

Shortcut class corresponds to class of the object, to which it refers.

Creating a Shortcut

A shortcut is created similarly to other repository objects. To create a shortcut, open parameters of created object and set the IMetabaseObjectCreateInfo.IsShortcut property to True, and specify description of the object, to which the shortcut refers, in the IMetabaseObjectCreateInfo.Shortcut property:

Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    ShortcutDesc: IMetabaseObjectDescriptor;
Begin
    MB := MetabaseClass.Active;
    CrInfo := MB.CreateCreateInfo;
    CrInfo.Id := "Shortcut_OBJTEST";
    CrInfo.Name := Shortcut for OBJTEST;
    CrInfo.Parent := MB.Root;
    CrInfo.Permanent := True;
    CrInfo.Shortcut := MB.ItemById("OBJTEST");
    CrInfo.IsShortcut := True;
    ShortcutDesc := MB.CreateObject(CrInfo);

After executing the example a shortcut for the OBJTEST object is created in the root of the repository.

Creating a Shortcut for an Object from Other Repository

To create a shortcut for an object from other repository, create the Repository Connection object in the current repository. After this specify repository connection in the code of the IMetabaseObjectCreateInfo.Link property, and description of object from other repository in the IMetabaseObjectCreateInfo.Shortcut property. Specify also class of the object, for which a shortcut is created, in the IMetabaseObjectCreateInfo.ClassId property:

Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    Link: IMetabaseObject;
    LinkInst: IMetabaseLinkInstance;
    ObjDesc, ShortcutDesc: IMetabaseObjectDescriptor;
Begin
    MB := MetabaseClass.Active;
    CrInfo := MB.CreateCreateInfo;
    CrInfo.Id := "Shortcut_Report_1";
    CrInfo.Name := Shortcut for Report_1;
    CrInfo.Parent := MB.Root;
    CrInfo.Permanent := True;
    Link := MB.ItemById("Link_Test").Bind;
    LinkInst := Link.Open(NullAs IMetabaseLinkInstance;
    ObjDesc := LinkInst.Metabase.ItemById("OBJTEST");
    CrInfo.Link := Link As IMetabaseLink;
    CrInfo.ClassId := ObjDesc.ClassId;
    CrInfo.Shortcut := ObjDesc;
    ShortcutDesc := MB.CreateObject(CrInfo);

After executing the example a shortcut is created in the repository root for the repository object, which is connected with the Link_Test repository.

Editing Objects via Shortcut

To edit an object (object description), to which the shortcut refers, get shortcut description and call the IMetabaseObjectDescriptor.Edit (IMetabaseObjectDescriptor.EditDescriptor) method. Cast the method result to the required interface and change object parameters or structure. For example, if a source object is an MDM dictionary, attribute name can be changed in the following by means of the shortcut to this object:

Var
    MB: IMetabase;
    SHDesc: IMetabaseObjectDescriptor;
    Dict: IRdsDictionary;
Begin
    MB := MetabaseClass.Active;
    SHDesc := MB.ItemById("SHORTCUT_TO_DICTIONARY");
    Dict := SHDesc.Edit As IRdsDictionary;
    Dict.Attributes.FindById("COUNTRY").Name := Dict.Attributes.FindById("World countries").Name;
    (Dict As IMetabaseObject).Save;

If the shortcut refers to the object from other repository, shortcut editing does not allow for changing object structure or description due to the current implementation features. To change the object, get its description, open it for edit, make required changes and save. Use the following code for this:

Sub Edit;
Var
    MB: IMetabase;
    SHDesc, ObjDesc: IMetabaseObjectDescriptor;
    Dict: IRdsDictionary;
Begin
    MB := MetabaseClass.Active;
    SHDesc := MB.ItemById("SHORTCUT_TO_DICTIONARY");
    ObjDesc := CheckShorcut(SHDesc);
    Dict := ObjDesc.Edit As IRdsDictionary;
    Dict.Attributes.FindById("COUNTRY").Name := Dict.Attributes.FindById("World countries").Name + "1";
    (Dict As IMetabaseObject).Save;
End Sub Edit;

Function CheckShorcut(Desc: IMetabaseObjectDescriptor): IMetabaseObjectDescriptor;
Var
    Result: IMetabaseObjectDescriptor;
Begin
    //If object shortcut is from other repository
    If Desc.IsLink Then
        Desc := Desc.Open(Null).Object;
    End If;
    //If shortcut refers to the object from the current repository, the recursive check is executed to get source object description
    If Desc.IsShortcut Then
        Result := CheckShorcut(Desc.Shortcut);
    Else
        Result := Desc;
    End If;
    Return Result;
End Function CheckShorcut;

The CheckShorcut function checks if object is a shortcut and recursively goes to the source object. After this it returns object's description. This function can also be used when a shortcut refers to the other shortcut (in the current or the other repository).

See also:

Examples | IMetabaseObjectDescriptor.IsShortcut | IMetabaseObjectDescriptor.IsLink