Applying the CoCreate function in Fore.NET

On developing application, the Fore language to initialize new objects use the New keyword, after which class is specified and the the class constructor is called. On working with Fore.NET analogs of Fore classes the New keyword and constructor are used, the default constructor (Create) can be not specified. If constructor has parameters in Fore, then 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);
    
//...

On 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, then on running Fore.NET code where COM objects of the platform are initialized, the error informing about absence of registered COM class can 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 and error it is required to change the Fore.NET code: to initialize COM objects, use the Prognoz.Platform.PiLibNet.Utils.ComCreator.Instance.CoCreate<Type>() function instead of the New operator. To use function, connect 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