RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TFields.FieldByName Method

Returns a field given its field name.

Pascal
function FieldByName(const FieldName: string): TField;
C++
__fastcall TField FieldByName(const AnsiString FieldName);

Call FieldByName to retrieve field information for a field when only the field's name is known. FieldName is the name of an existing field. FieldByName returns the TField component for the specified field. If the field can not be found, an exception is raised. 

When the Fields array contains ADT fields, you can use FieldByName to access the subfields of those ADT fields. To access subfields, specify FieldName as the name of the subfield qualified by the name of the ADT field, as in the following:

CityEdit.Text := Customer.FieldByName('Address.City').AsString;

 

CityEdit->Text = Customer->FieldByName("Address.City")->AsString;

FieldByName is especially useful when you do not have access to the underlying table and cannot use persistent field components.

Note: FieldByName differs from the FindField method only when the named field is not in the list. When the field is not found, FieldByName raises an exception, while FindField returns nil (Delphi) or NULL (C++).
 

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