RAD Studio VCL Reference
TDataSet.FieldValues Property

Provides access to the values for all fields in the active record for the dataset

property FieldValues [const FieldName: string]: Variant;
__property Variant FieldValues[AnsiString const FieldName];

Use FieldValues to read and write values for fields in a dataset. FieldName is the name of a field to read from or write to.  

FieldName can represent simple field names, qualified field names for subfields of an object field, or aggregated fields such as can be found in the AggFields property. Because of this flexibility, it is often preferable to use the FieldValues property (or the FieldByName method) rather than the Fields, FieldList, or AggFields properties, all of which present a more limited selection of the dataset's fields. 

FieldValues accepts and returns a Variant, so it can handle and convert fields of any type. Because FieldValues is the default property for TDataSet, you can omit the property name when referencing this property. For example, the following statements are semantically identical and write the value from an edit box into an integer field:

Customers.FieldValues['CustNo'] := Edit1.Text;
Customers['CustNo'] := Edit1.Text;


Customers->FieldValues["CustNo"] = Edit1->Text;

Note: Because FieldValues always uses Variants, it may be a somewhat slower method of accessing data, than using a field's native format (for example, using a field's AsXXX property), especially in applications that process large amounts of data.

Delphi Examples: 


This example appends a new record to a table or client
dataset when the user clicks a button. The two fields
Field1 and Field2 are filled from the contents of two edit
controls.  This example requires a populated TTable or
TDataSet with the appropriate field values.
procedure TForm1.Button1Click(Sender: TObject);
  Customers.FieldValues['Field1'] := StrToInt(Edit1.text);
  Customers.FieldValues['Field2'] := Edit2.text;


Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!