Reading the AsString property returns the abbreviated class name of the field component enclosed in parentheses. The abbreviated class name is built by stripping the leading 'T' from the class name and removing the trailing word 'FIELD', except in the case of TField where that would leave an empty string. Thus, the abbreviated class name of TField is "FIELD", the abbreviated class name of TVarBytesField is "VarBytes", and so on.

Trying to set the AsString property raises an exception.

Descendants of TField that represent string fields or that support conversions between the field's Value property and a string override AsString to read and write the value of the field as a different, more meaningful, string.

/*
This example uses a button to copy the value of a field in
the previous record into the corresponding field in the
current record. The field to copy is specified by using
FindField and the name of the field.
*/void__fastcall TForm1::Button2Click(TObject *Sender)
{
TBookmark SavePlace;
Variant PrevValue;
// get a bookmark so that we can return to the same record
SavePlace = Customers->GetBookmark();
try
{
// move to prior record}
Customers->FindPrior();
// get the value// This is the safe way to get 'CustNo' field
PrevValue = Customers->FindField("Field2")->Value;
// This is *not* the safe way to change 'CustNo' field// PrevValue = Customers->Fields->Fields[1]->Value;/*
Move back to the bookmark
this may not be the next record anymore
if something else is changing the dataset asynchronously
*/
Customers->GotoBookmark(SavePlace);
// Set the value
Customers->Edit();
// This is the safe way to change 'CustNo' field
Customers->FindField("Field2")->AsString = PrevValue;
// This is *not* the safe way to change 'CustNo' field// Customers->Fields->Fields[1]->AsString = PrevValue;// Free the bookmark
}
__finally
{
Customers->FreeBookmark(SavePlace);
};
}
/*
To ensure that the button is disabled when there is no
previous record, the OnDataChange event of the DataSource
detects when the user moves to the beginning of file (BOF
property becomes true), and disables the button. Detection
occurs on scrolling and editing, not selection with the mouse.
*/void__fastcall TForm1::DS2DataChange(TObject *Sender, TField *Field)
{
if (Customers->Bof)
Button2->Enabled = False;
else
Button2->Enabled = True;
}

{
This example uses a button to copy the value of a field in
the previous record into the corresponding field in the
current record. The field to copy is specified by using
FindField and the name of the field.
}procedure TForm1.Button1Click(Sender: TObject);
var
SavePlace: TBookmark;
PrevValue: Variant;
beginClose;
with Customers dobegin{ get a bookmark so that we can return to the same record }
SavePlace := GetBookmark;
try{ move to prior record}
FindPrior;
{ get the value }{ This is the safe way to get 'CustNo' field }
PrevValue := FindField('Field2').Value;
{ This is *not* the safe way to change 'CustNo' field }// PrevValue := Fields[1].Value;{ Move back to the bookmark
this may not be the next record anymore
if something else is changing the dataset asynchronously }
GotoBookmark(SavePlace);
{ Set the value }
Edit;
{ This is the safe way to change 'CustNo' field }
FindField('Field2').AsString := PrevValue;
{ This is *not* the safe way to change 'CustNo' field }// Fields[1].AsString := PrevValue;{ Free the bookmark }finally
FreeBookmark(SavePlace);
end;
end;
end;
{
To ensure that the button is disabled when there is no
previous record, the OnDataChange event of the DataSource
detects when the user moves to the beginning of file (BOF
property becomes true), and disables the button. Detection
occurs on scrolling and editing, not selection with the mouse.
}procedure TForm1.DS2DataChange(Sender: TObject; Field: TField);
beginif Customers.Bof then
Button1.Enabled := False
else
Button1.Enabled := True;
end;