Step 10: Get the desired fields from the record

<< Click to Display Table of Contents >>

Navigation:  Application development > Introduction to BDE programming > BDE Programming in Delphi > Basic procedure >

Step 10: Get the desired fields from the record

Previous pageReturn to chapter overviewNext page

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.

var

 Company: array [0..30] of Char;

 IsBlank: BOOL;

begin

 …

 Check(DbiGetField(

   hCur,            // Cursor which contains the record

   2,               // Field Number of the "Company" field

   RecordBuffer,    // Buffer containing the record

   pBYTE(@Company), // Variable for the Company field value

   IsBlank));        // Is the field blank?

 …

end;

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.