FieldItem(Index: Integer): IForeVar;
FieldItem(Index: Integer): Prognoz.Platform.Interop.Fore.IForeVar;
Index. Field index.
The FieldItem method returns the class field with the specified index.
The number of available fields can be obtained using the FieldsCount method.
Executing the example requires a unit with the MODULE identifier. The following class is added in the unit:
Class Test: Object
Public A: Integer;
Public B: String;
Public C: DateTime;
Public Constructor Create;
Begin
a := 100;
b := "Test";
c := DateTime.Now;
End Constructor Create;
End Class Test;
Add links to the Fore, Metabase system assemblies.
Sub UserProc;
Var
ForeService: IForeServices;
Runtime: IForeRuntime;
Assm: IForeAssembly;
FClass: IForeClass;
ClassInst: IForeObject;
FSub: IForeSub;
Field: IForeVar;
c, i: Integer;
Begin
ForeService := MetabaseClass.Active As IForeServices;
Runtime := ForeService.GetRuntime;
//Load assembly
Assm := Runtime.BindToAssembly("MODULE");
//Get class
FClass := Assm.BindToClass("Test");
//Create a class instance
ClassInst := FClass.CreateObject;
//Call the constructor initializing fields values
FSub := FClass.BindToMethod("Create");
FSub.Self := ClassInst;
FSub.Invoke;
//View fields
c := ClassInst.FieldsCount;
For i := 0 To c - 1 Do
Field := ClassInst.FieldItem(i);
Debug.WriteLine(Field.Name + " : " + Field.Value);
End For;
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;
Field: IForeVar;
c, i: Integer;
Begin
ForeService := Params.Metabase As IForeServices;
Runtime := ForeService.GetRuntime();
//Load assembly
Assm := Runtime.BindToAssembly("MODULE");
//Get class
FClass := Assm.BindToClass("Test");
//Create a class instance
ClassInst := FClass.CreateObject();
//Call the constructor initializing fields values
FSub := FClass.BindToMethod("Create");
FSub.Self := ClassInst;
FSub.Invoke();
//View fields
c := ClassInst.FieldsCount();
For i := 0 To c - 1 Do
Field := ClassInst.FieldItem(i);
System.Diagnostics.Debug.WriteLine(Field.Name + " : " + Field.Value);
End For;
End Sub;
On executing the example, the specified unit is loaded to execution environment. The class instance will be created, the constructor will be executed that initializes the fields values.After that, values of all fields will be displayed to the development environment console.
See also: