|
<< Click to Display Table of Contents >> Step 10: Get the desired fields from the record |
![]() ![]()
|
Now you are ready to get the field value out of the record buffer and into an application variable. Use DbiGetField to retrieve the values of individual fields.
In this example, DbiGetField is used to retrieve the value of the field named Company. Specify the cursor containing the data in the hCursor argument with the hCur variable. Since Company is the second field in the table Customer.db, pass 2 for the iField argument. Indicate the record buffer RecordBuffer in the pRecBuf argument. Specify the memory variable (Company) into which to store the retrieved field value in the pDest argument. The last argument is a var parameter into which the BDE stores a BOOL value indicating whether the field is blank. This operation returns the string "Kauai Dive Shoppe," the company in the first record of the Customer.db table.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
…
unsigned char* CompanyBuf;
BOOL isBlank = 0;
…
CompanyBuf = (unsigned char*) malloc(31);
Check(DbiGetField(
hCur, // Cursor which contains the record
2, // Field Number of the "Company" field
pRecBuf, // Buffer containing the record
CompanyBuf, // Variable for the Company field value
isBlank)); // Is the field blank?
Label1->Caption = reinterpret_cast<char*>(CompanyBuf);
…
}
This example makes assumptions about which field is at which ordinal position within the table, as well as the size of the field. In general, it is recommended to use DbiGetFieldDescs to get information about a field before retrieving it. This provides the application with very specific information about a field that may not be known at design-time.
It should also be pointed out that, with the exception of BLOB fields, DbiGetField is used to retrive the values of all the fields of a cursor – one at a time, of course.