Applying the CoCreate function in Fore.NET

When developing applications in the Fore language to initialize new objects use the New keyword, after which a class is specified and a class constructor is called. When working with Fore.NET analogs of Fore classes the New keyword and constructor are also used, the default constructor (Create) does not need to be specified. If a constructor has parameters in Fore, the constructor is called as method in Fore.NET.

Example of Object Initialization in Fore and Fore.NET:

Var
    
//...
    ManagerFactory: IMetabaseManagerFactory;
    Color: IGxColor;
    
//...
Begin
    
//...
    ManagerFactory := New MetabaseManagerFactory.Create;
    Color := 
New GxColor.CreateRGB(255255255);
    
//...

Imports Prognoz.Platform.Interop.Drawing;
Imports Prognoz.Platform.Interop.Metabase;

//...
Var
    
//...
    ManagerFactory: IMetabaseManagerFactory;
    Color: GxColor;
    
//...
Begin
    
//...
    ManagerFactory := New MetabaseManagerFactory();
    ManagerFactory := 
New MetabaseManagerFactory.Create();
    Color := New GxColorClass_2();
    Color.CreateRGB(
255255255);
    
//...

When working in Fore.NET this object initialization method is available if Foresight Analytics Platform installed using installer without Reg-free COM registration is in use.

If installer uses Reg-free COM registration, on running Fore.NET code where COM objects of the platform are initialized, the error informing about absence of registered COM class may occur. The error occurs because .NET environment cannot create a class instance because of the absence of manifest describing COM classes in executable classes. To correct the error, change the Fore.NET code: to initialize COM objects, use the Prognoz.Platform.PiLibNet.Utils.ComCreator.Instance.CoCreate<Type>() function instead of the New statement. To use the function, add link to the WinForms.Utils system assembly:

Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.PiLibNet.Utils;

//...
Var
    
//...
    ManagerFactory: IMetabaseManagerFactory;
    Driver: DalOrcl8Driver;
    
//...
Begin
    
//...
    ManagerFactory := ComCreator.Instance.CoCreate<MetabaseManagerFactoryClass>();
    Driver := ComCreator.Instance.CoCreate<DalOrcl8DriverClass>();
    
//...

The CoCreate function use is mandatory in code that will be further called via the ForeExec web service operation.

See also:

Developers Knowledge Base