EPUB | CHM | PDF

TDataSet.Properties.Fields

Top Previous Next

Lists all non-aggregate field components of the dataset.

Syntax:

property Fields: TFields;

Description:

Use Fields to access field components. If fields are generated dynamically at runtime, the order of field components in Fields corresponds directly to the order of columns in the table or tables underlying a dataset. If a dataset uses persistent fields, then the order of field components corresponds to the ordering of fields specified in the Fields editor at design time.

When ObjectView is True, the fields are stored hierarchically, meaning any child fields of an object field are referenced by the object field and don't appear sequentially after the object field in the TFields.Fields array. When ObjectView is False, the fields are stored sequentially, or flattened out, meaning any child fields of an object field are stored sequentially in the TFields.Fields array.

Accessing fields with the Fields property is useful for applications that:

Iterate over some or all fields in a dataset.

Work with underlying tables whose internal data structure is unknown at runtime.

If an application knows the data types of individual fields, then it can read or write individual field values through the Fields property. For example, the following statement assigns a field value to the Text property of an edit box:

Edit1.Text := CustMySQLTable.Fields.Fields[6].AsString;

note The preferred method for retrieving and assigning field values is to use persistent fields or the FieldByName method.

The following statements assign a value from an edit box to a field:

CusTMySQLTable.Edit;
CusTMySQLTable.Fields.Fields[6].AsString := Edit1.Text;
CusTMySQLTable.Post;

See also: Example: FieldCount,Fields,FieldName