Data.DB.TDataSet.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 TDataSet

Description

Finds a field based on its name.

Call FieldByName to retrieve field information for a field given its name. FieldName is the name of an existing field. FieldByName returns the TField component that represents the specified field. If the specified field does not exist, FieldByName raises an EDatabaseError exception.

FieldName can be the name of a simple field, the name of a subfield of an object field that has been qualified by the parent field's name, or the name of an aggregated field. Because of this flexibility, it is often preferable to use FieldByName rather than the Fields property or the AggFields property.

An application can directly access specific properties and methods of the field returned by FieldByName. For example, the following statement determines if a specified field is a calculated field:

Delphi:

if Customers.FieldByName('FullName').Calculated then
  // …

C++:

if (Customers->FieldByName("FullName")->Calculated)
  // …

FieldByName is especially useful at design time for developers who are creating database applications, but do not have access to the underlying table and therefore cannot use persistent field components.

Tip: To retrieve or set the value for a specific field, call the default dataset method FieldValues instead of FieldByName.

See Also


Code Examples