Delphi Examples: DbiGetFieldDescs

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiGetFieldDescs

Return to chapter overview

Retrieve a list of descriptors for all fields in the table associated with the given TTable:

This function prints out the field numbers and names of the table. This example uses the following input:

 fDbiGetFieldDescs(Table1);

 

The procedure is:

procedure ShowFields(T: TTable);

var

  curProp: CURProps;

  pfldDes, pCurFld: pFLDDesc;

  // pfldDes is a pointer to a list of field descriptors.

  // It must be allocated with (iFields * sizeof(FLDDesc))

  // where iFields is a field in the structure curProps

  // from DbiGetCursorProps

  // pCurFld is a pointer the description of one field in the list.

  i: Integer;          // counter

  MemSize: Integer;

  FieldList: String;

begin

 Check(DbiGetCursorProps(T.Handle, curProp));

 // Get enough memory for one field desc times the # of fields

 MemSize := curProp.iFields * SizeOf(FLDDesc);

 pfldDes := AllocMem(MemSize);

try

   pCurFld := pfldDes;

   Check(DbiGetFieldDescs(T.Handle, pfldDes));

   I := 0;

   FieldList := '';

  while (i < curProp.iFields) do begin

     FieldList := FieldList + Format('%d - %s'#13#10,[pCurFld^.iFldNum,

       pCurFld^.szName]);

     // increment pointer to the next record

     inc(pCurFld);

     inc(i);

  end;

finally

   ShowMessage(FieldList);

   FreeMem(pfldDes, MemSize);

end;