Appearance
Dataset.FieldByNumber
Dataset[.Query].Fields.FieldByNumber
Declaration
function FieldByNumber( const FieldIndex : integer) : TField
Example
pascal
procedure OnMapEvent(var Value:Variant);
begin
Value := DATAVIEW.Query.Fields.FieldByNumber(3).Value; // returns the value for the 3rd field
end;Description
Returns the field object for the field with the given index. The field array is a 1-based array therefore the above example returns the 3rd field in the list.
Fields are not normally referenced using their index because this can change if you add or delete fields from the dataset. You should reference fields using their name to avoid this issue, and only reference by index if you have a particular reason (such as looping all fields in the dataset).
When using the FieldByNumber function with a Source or Destination Dataview, .Query must be included as shown in the example above. When using the FieldByNumber function with a script dataset (including the global datasets Data1, Data2, etc), .Query is not included.
Also note that for a .Query dataset for a Dataview, the dataset will include any fields added by Flow, such as ID and MASTER_ID for a Dataview associated with a File Definition, or "Magic Link" fields for a DB Definition.
The reference .Fields.Fields[i] is equivalent to .Fields.FieldByNumber(i)
(Previously referred to as FieldByIndex, until corrected in October 2013.)