Delphi Examples: DbiGetIndexDescs

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiGetIndexDescs

Return to chapter overview

Get the properties of all indexes for TTable T:

This function loops through all the indexes and shows the names and fields in the key. This example uses the following input:

 ShowIndexDescs(Table1);

 

The procedure is:

procedure ShowIndexDescs(T: TTable);

const

 IDXStr = '%sIndex name: %s. Number of fields in key: %d'#13#10;

var

 CurProp: CURProps;

 pIndexDesc, pTmpMem: pIdxDesc;

 i, MemSize: Integer;

 ShowString, IDXName: String;

begin

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

 MemSize := CurProp.iIndexes * sizeof(IDXDesc);

 pIndexDesc := AllocMem(MemSize);

try

   pTmpMem := pIndexDesc;

   Check(DbiGetIndexDescs(T.Handle, pIndexDesc));

   i := 0;

   ShowString := '';

  while (i < curProp.iIndexes) do begin

    with pTmpMem^ do begin

       // primary index does not have a name for PARADOX tables }

      if bPrimary and (StrComp(curProp.szTableType, szParadox) = 0) then

         IDXName := 'Primary'

      else

         IDXName := szName;

       ShowString := Format(IDXStr, [ShowString, IDXName, iFldsInKey])

    end;

     // increment pointer to the next record

     inc(pTmpMem);

     inc(i);

  end;

finally

   FreeMem(pIndexDesc, MemSize);

   ShowMessage(ShowString);

end;

end;