Skip to main content

FieldByIndex

function FieldByIndex(const FieldIndex: Integer): TvxField;

Example

function FirstFieldText(const View: TdaCDSQueryDataView): string;
begin
Result := View.FieldByIndex(0).AsString;
end;

Usage

FieldByIndex returns the zero-based field-list entry from the client dataset; ordering is metadata-dependent and an invalid index raises.

  • Prefer FieldByName for stable mapping logic.
  • Use index access only when the exact DataView field order is part of the governed configuration.
  • Do not retain the reference after the dataset closes/recreates its fields.

Additional Technical Info

FieldByIndex returns one TField object from the concrete view's client dataset. PascalScript exposes the return as TvxField, an API overlay over the actual native field descendant.

Source-backed behaviour

The hidden base returns nil. Both shipped descendants override it with FQuery.Fields[FieldIndex]. The index is zero-based collection order. Delphi's field list checks the range and raises for negative or >= FieldCount; the method does not return nil for an invalid index.

Field order is configured/generated metadata and can be changed through TField.Index; it is not a stable database ordinal. For file/CDS views, generated ID and MASTER_ID fields occupy important early positions, and Insert relies on indexes 0/1. The returned object remains owned by the dataset and must not be freed.

Official terminal references

Created 2026-07-15