Application of Fore in Fore.NET

A number of interfaces is implemented in .NET units/forms to use resources of the assemblies/forms/units written in the Fore language. Connect the Prognoz.P5.Interop.Fore assembly on the .NET assembly tab of the links configuration window of .NET assembly to work with Fore objects. For more convenient use of not qualified identifiers in the area of import, it is possible to add a line to import given assembly namespace content:

Imports Prognoz.Platform.Interop.Fore;

The following interfaces could be used to work with units or forms of Fore:

Interface Brief description
IForeServices The basic interface containing properties and methods used to work with Fore-objects of platform.
IForeRuntime The interface containing properties and methods used to work with execution context of platform. In this context work with all assemblies is performed.
IForeAssembly The interface containing properties and methods used to work with Fore assemblies. Separate units and forms not being a part of any assembly, are compiled as separate assembly and are also implemented by the given interface.
IForeClass The interface containing properties and methods used to work with Fore types implemented in Fore assemblies. Some of the interface properties and methods:
  • SubsCount and SubItem. They allow to work with collection of all methods of the class, including the GET and SET methods that implement properties.
  • BindToMethod. Allows to get class method by name. The GET and SET methods that implement properties have the following signature: .Get<Name> and .Set<Name>, where <Name> is property name.
  • CreateObject. Creates a class object instance.

NOTE. Due to features of implementation related with creating of object instances by means of the CreateObject method, the obtained object completely corresponds to the class, but class constructors are not called on initializing: the default constructor or any constructors implemented in the class are not called. This causes that the obtained object may not have the values of properties or fields, which were determined by the logic of its work. If required, the constructor may be obtained and called by the BindToMethod method.

IForeSub The interface containing properties and methods used to work with Fore methods implemented in Fore types.
IForeObject The interface containing properties and methods used to work with instances of objects of Fore types. Some of the interface properties and methods:
  • BindToField. Allows to get field value by name for the class instance.

NOTE. These interfaces are available only in Fore.Net language, or in languages where platform library Prognoz.Platform.Interop.Fore.dll is used.

Example of the Code in the Fore.NET Language

Executing this example requires a .NET assembly with .NET form created in it. The button is placed on the .NET form. The repository contains form or unit with the UserFunc identifier. The TestClass class is implemented in repository, the Test function is implemented in class.

Private Sub button1_Click(sender: System.Object; e: System.EventArgs);
Var
    Svc: IForeServices;
    Run: IForeRuntime;
    Assembly: IForeAssembly;
    FClass: IForeClass;
    FSub: IForeSub;
    FObj: IForeObject;
    v: object;
Begin
    Svc := Self.Metabase As IForeServices; //Receiving object for work with Fore
    Run := Svc.GetRuntime(); //Receiving context, in which Fore methods are executed
    Run.LoadAssembly("UserFunc"); //Loading assembly Fore into execution context
    Assembly := Run.BindToAssembly("UserFunc"); //Receiving compiled assembly
    FClass := Assembly.BindToClass(TestClass); //Receiving Fore class
    FObj := FClass.CreateObject(); //Creating class object
    FSub := FClass.BindToMethod("Test"); //Receiving method of this class
    FSub.Self := FObj; //Indicating object, for which method is executed
    FSub.Invoke(); //Executing method
    v := FSub.ResultValue; //Receiving execution result
End Sub;

Pressing the button calls the Fore method Test. The "v" variable contains execution result.

If it is required to call a class constructor, enter the following code strings to the example:

Var
    //...
    FConstructor: IForeSub;
    //...
Begin
    //...
    FObj := FClass.CreateObject(); //Creating class object
    //Call the Create constructor without parameters
    FConstructor := FClass.BindToMethod("Create");
    FConstructor.Self := FObj;
    FConstructor.Invoke();
    //Call the CreateEx constructor with parameters
    FConstructor := FClass.BindToMethod("CreateEx");
    FConstructor.Self := FObj;
    FConstructor.Params.Item(0).Value := "Test";
    FConstructor.Params.Item(1).Value := 100;
    FConstructor.Invoke();
    //...

If the performed Test method has parameters, enter the following code strings to the example:

    //...
    FSub.Self := FObj; //Indicating object, for which method is executed
    FSub.Params.Item(0).Value := 10//First parameter value
    FSub.Params.Item(1).Value := 20//Second parameter value
    FSub.Invoke(); //Executing method
    v := FSub.ResultValue; //Receiving execution result
    //...

See also:

Introduction