SetFieldValue(FieldName: String; Value: Variant; Type: ForeVariantType);
SetFieldValue(FieldName: String; Value: Variant; Type: Prognoz.Platform.Interop.KeFore.ForeVariantType);
FieldName. Class field name.
Value. Value to be set for for field.
Type. Type of selected value.
The SetFieldValue method sets the specified value to class field.
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
Runtime.LoadAssembly("MODULE");
Assm := Runtime.BindToAssembly("MODULE");
//Get class
FClass := Assm.BindToClass("A");
//Create class instance and set values to 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 values
Param := FSub.Params.ParamByName("obj");
Param.Value := ClassInst.Object;
//Execute method
FSub.Invoke;
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;
FSub: IForeSub;
Param: IForeSubParam;
Begin
ForeService := Params.Metabase As IForeServices;
Runtime := ForeService.GetRuntime();
//Load assembly
Runtime.LoadAssembly("MODULE");
Assm := Runtime.BindToAssembly("MODULE");
//Get class
FClass := Assm.BindToClass("A");
//Create class instance and set values to its fields
ClassInst := FClass.CreateObject();
ClassInst.SetFieldValue("FieldA", 100, ForeVariantType.fvtInteger);
ClassInst.SetFieldValue("FieldB", "Field", ForeVariantType.fvtString);
//Get method
FSub := Assm.BindToSub("Test");
//Set method parameter values
Param := FSub.Params.ParamByName("obj");
Param.Value := ClassInst.Object;
//Execute method
FSub.Invoke();
End Sub;
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: