Data.DB.TFields.FieldByName

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function FieldByName(const FieldName: string): TField;

C++

TField* __fastcall FieldByName(const System::UnicodeString FieldName);

Properties

Type Visibility Source Unit Parent
function public
Data.DB.pas
Data.DB.hpp
Data.DB TFields

Description

Returns a field given its field name.

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++).

See Also