KeyRef.FieldIndex(Integer) Method

Version: Available or changed with runtime version 1.0.

Gets the FieldRef of the field that has this index in the key referred to by the KeyRef variable. Returns an error if no key is selected.


Field :=   KeyRef.FieldIndex(Index: Integer)


 Type: KeyRef
An instance of the KeyRef data type.

 Type: Integer
The input index.

Return Value

 Type: FieldRef
The FieldRef that refers to the field with this index in the key.


The first field in the index must have index 1, the second index 2, and so on. The last field must have index = FieldCount. If the index is out of the range supplied or if no table is selected, the method returns an error.


The following example displays the caption of a field in a record. The table with ID 18 (the Customer table) is open with a reference. The Keyref for the record is retrieved by using the KeyIndex Method (RecordRef). The method retrieves the second key in the record and stores the value in the varKeyRef variable. The varKeyRef variable is then used to return the FieldRef. The varFieldRef variable is used to display the caption of the field.

    RecRef: RecordRef;
    varKeyRef: KeyRef;
    varFieldRef: FieldRef;
    varKeyRef := RecRef.KeyIndex(2);  
    varFieldRef := varKeyRef.FieldIndex(1);  
    Message('The Field name is: %1' ,varFieldRef.Caption);  

See Also

KeyRef Data Type
Get Started with AL
Developing Extensions