IForeObject.SetFieldValue

Syntax

SetFieldValue(FieldName: String; Value: Variant; Type: ForeVariantType);

Parameters

FieldName. Class field name.

Value. Value to be set for for field.

Type. Type of selected value.

Description

The SetFieldValue method sets the specified value to class field.

Example

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

Class A: Object
    
Public a: Integer;
    
Public b: String;
End Class A;

Sub Test(obj: A);
Begin
    Debug.WriteLine(obj.a);
    Debug.WriteLine(obj.b);
End Sub Test;

Add a link to the Fore, Metabase system assembly.

Sub UserProc;
Var
    ForeService: IForeServices;
    Runtime: IForeRuntime;
    Assm: IForeAssembly;
    FClass: IForeClass;
    ClassInst: IForeObject;
    FSub: IForeSub;
    Param: IForeSubParam;
Begin
    ForeService := MetabaseClass.Active As IForeServices;
    Runtime := ForeService.GetRuntime;
    //Load assembly
    Assm := Runtime.BindToAssembly("MODULE");
    //Get class
    FClass := Assm.BindToClass("A");
    //Create a class instance and set values for its fields
    ClassInst := FClass.CreateObject;
    ClassInst.SetFieldValue("FieldA"100, ForeVariantType.Integer);
    ClassInst.SetFieldValue("FieldB""Field", ForeVariantType.String);
    //Get method
    FSub := Assm.BindToSub("Test");
    //Set method parameter value
    Param := FSub.Params.ParamByName("obj");
    Param.Value := ClassInst.Object;
    //Execute method
    FSub.Invoke;
End Sub UserProc;

On executing the example, the specified unit is loaded to execution environment. The class instance will be created and its field values will be set. The obtained class instance will be sent as parameter to the Test method, after that the method will be launched for execution.

See also:

IForeObject