IForeObject.FieldItem

Syntax

FieldItem(Index: Integer): IForeVar;

Parameters

Index. Field index.

Description

The FieldItem method returns the class field with the specified index.

Comments

The number of available fields can be obtained using the FieldsCount method.

Example

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 that initializes values for fields
    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;

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:

IForeObject