IForeObject.BindToField

Syntax

BindToField(FieldName: String): 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 class 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
    Assm := Runtime.BindToAssembly("MODULE");
    //Get class
    FClass := Assm.BindToClass("B");
    //Create a 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;

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