IForeObject.BindToField

Syntax

BindToField(FieldName: String): IForeVar;

BindToField(FieldName: String): Prognoz.Platform.Interop.KeFore.IForeVar;

Parameters

FieldName. Class field name.

Description

The BindToField method returns class field by name.

Comments

The method returns Null, if class does not have field with the specified name.

Example

Executing the example requires a unit with the MODULE identifier. The following code is added in the unit:

Class B: Object
    
Public X: Double;

    
Public Function LogX: Double;
    
Begin
        
Return Math.Log10(X)
    
End Function LogX;
End Class B;

Add a link to the Fore, Metabase system assembly.

Sub UserProc;
Var
    ForeService: IForeServices;
    Runtime: IForeRuntime;
    Assm: IForeAssembly;
    FClass: IForeClass;
    ClassInst: IForeObject;
    Field: IForeVar;
    FSub: IForeSub;
Begin
    ForeService := MetabaseClass.Active 
As IForeServices;
    Runtime := ForeService.GetRuntime;
    
//Load assembly
    Runtime.LoadAssembly("MODULE");
    Assm := Runtime.BindToAssembly(
"MODULE");
    
//Get class
    FClass := Assm.BindToClass("B");
    
//Create class instance, get method and set field value
    ClassInst := FClass.CreateObject;
    FSub := FClass.BindToMethod(
"LogX");
    FSub.Self := ClassInst;
    
//Field
    Field := ClassInst.BindToField("X");
    Field.Value := 
123.456;
    FSub.Invoke;
    Debug.WriteLine(FSub.ResultValue);
    
//New field value   
    Field.Value := 654.321;
    FSub.Invoke;
    Debug.WriteLine(FSub.ResultValue);
End Sub UserProc;

Imports Prognoz.Platform.Interop.Fore;
Imports Prognoz.Platform.Interop.Metabase;

Public Shared Sub Main(Params: StartParams);
Var
    ForeService: IForeServices;
    Runtime: IForeRuntime;
    Assm: IForeAssembly;
    FClass: IForeClass;
    ClassInst: IForeObject;
    Field: IForeVar;
    FSub: IForeSub;
Begin
    ForeService := Params.Metabase 
As IForeServices;
    Runtime := ForeService.GetRuntime();
    
//Load assembly
    Runtime.LoadAssembly("MODULE");
    Assm := Runtime.BindToAssembly(
"MODULE");
    
//Get class
    FClass := Assm.BindToClass("B");
    
//Create class instance, get method and set field value
    ClassInst := FClass.CreateObject();
    FSub := FClass.BindToMethod(
"LogX");
    FSub.Self := ClassInst;
    
//Field
    Field := ClassInst.BindToField("X");
    Field.Value := 
123.456;
    FSub.Invoke();
    System.Diagnostics.Debug.WriteLine(FSub.ResultValue);
    
//New field value   
    Field.Value := 654.321;
    FSub.Invoke();
    System.Diagnostics.Debug.WriteLine(FSub.ResultValue);
End Sub;

On executing the example, the specified unit is loaded to execution environment. The class instance will be created, the LogX function and the X field will be obtained. Value is set twice for field and the LogX function is executed also twice. The results of function work will be displayed to the development environment console.

See also:

IForeObject