Creating a View

Executing the example requires that the repository contains a database with the BD identifier.

Sub UserProc;
Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    MObj: IMetabaseObject;
    View: IView;
Begin
    MB := MetabaseClass.Active;
    CrInfo := MB.CreateCreateInfo;
    CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_VIEW;
    CrInfo.Id := "NewView";
    CrInfo.Name := "New view";
    CrInfo.Parent := MB.Root;
    MObj := MB.CreateObject(CrInfo).Edit;
    View := MObj As IView;
    View.Database := Mb.ItemById("BD").Bind As IDatabase;
    View.NativeName := "New_View";
    View.Sql := "Select * From Table_1";
    View.ForceCreate := True;
    MObj.Save;
End Sub UserProc;

After executing the example, the new view is created in repository root. This view is built on data contained in the table with a physical name Table_1. It is possible to save this view with incorrect SQL query.

See also:

Examples