Modifier

Partager via


RecordRef.Field(Integer) Method

Version: Available or changed with runtime version 1.0.

Gets a FieldRef for the field that has the number FieldNo in the table that is currently selected. If no field has this number, the method returns an error.

Syntax

Field :=   RecordRef.Field(FieldNo: Integer)

Parameters

RecordRef
 Type: RecordRef
An instance of the RecordRef data type.

FieldNo
 Type: Integer
The number that the field has in the table that is currently selected. This is the field for which you want the FieldRef.

Return Value

Field
 Type: FieldRef
A new FieldRef of the record

Remarks

This method returns an error if the record is not opened and if the field is not found.

You might obtain better performance by using the FieldIndex Method (RecordRef).

Example

The following example opens table 18 (Customer) as a RecordRef variable that is named MyRecordRef. MyRecordRef uses the Field method to create a reference to the No. field (field 1). The value in the No. field is then set to a specified record No. In this example, the record is set to 30000. The Find Method (RecordRef) method.md records for record 30000. If record is found, the Field method retrieves the value in the Name field (field 2), stores it in the varOldName variable and displays it in a message box. The Value Method (FieldRef, TestPage Field) changes the value in the Name field to a new name. In this example, the new name is ‘Contoso’. The table is then modified to reflect this change and the new value in the Name field is retrieved and displayed in a message box. You can specify any record in the table and change the value in the Name field.

var
    MyRecordRef: RecordRef;
    MyFieldRef: FieldRef;
    varOldName: FieldRef;
    varNewName: Text;
    MyRecord: Code;
begin  
    MyRecord := '30000';  
    varNewName := 'Contoso';  
    MyRecordRef.Open(18);  
    MyFieldRef := MyRecordRef.Field(1);  
    MyFieldRef.Value := MyRecord;  
    if MyRecordRef.Find('=') then begin  
      varOldName := MyRecordRef.Field(2);  
      Message('Old Name: %1', varOldName);  
      varOldName.Value := varNewName;  
      MyRecordRef.Modify;    
      Message('New Name: %1', MyRecordRef.Field(2));  
    end;  
end;

See Also

RecordRef Data Type
Get Started with AL
Developing Extensions