|
<< Click to Display Table of Contents >> Delphi Examples: DbiGetIndexForField |
![]() ![]()
|
Return the description of any useful index on the specified field.
You can also use this function can just to check if an index exists for the given field. When you pass a handle of the table, a valid field number, and a TStringList, the procedure appends the information accessed from a IdxDesc Record to the TStringList. This example uses the following input:
fDbiGetIndexForField(DBASEAnimals.handle, 1, False, MyIndexInfo);
The procedure is:
procedure fDbiGetIndexForField(hCursor: hDBICur; Field: TField; IndexInfo: TStringList);
function BoolVal(InBool: Boolean): String;
begin
if InBool then Result:= 'True'
else Result:= 'False';
end;
var
KeyArray: String;
x: Word;
MyidxDesc: IdxDesc;
begin
Check(DbiGetIndexForField(hCursor, Field.Index + 1, True, MyidxDesc));
with IndexInfo do begin
Add('Index Name: ' + MyidxDesc.szname);
Add('Index Number: ' + IntToStr(MyidxDesc.iIndexId));
Add('Tag Name (dBASE): ' + MyidxDesc.szTagName);
Add('Index Format: ' + MyidxDesc.szformat);
Add('Primary: ' + BoolVal(MyidxDesc.bPrimary));
Add('Descending: ' + BoolVal(MyidxDesc.bDescending));
Add('Maintained: ' + BoolVal(MyidxDesc.bMaintained));
Add('Subset: ' + BoolVal(MyidxDesc.bSubset));
Add('ExpIdx: ' + BoolVal(MyidxDesc.bExpIdx));
Add('Fields In Key: ' + IntToStr(MyidxDesc.iFldsInKey));
Add('Key Length: ' + IntToStr(MyidxDesc.iKeyLen));
Add('Out of Date: ' + BoolVal(MyidxDesc.bOutofDate));
Add('Key Expression Type: ' + IntToStr(MyidxDesc.iKeyExpType));
for x:= 0 to (MyidxDesc.iFldsInKey –1) do
KeyArray:= KeyArray + IntToStr(MyidxDesc.aiKeyFld[x]) + ', ';
Add('Field Numbers used in Key: ' + KeyArray);
Add('Key Expression: ' + MyidxDesc.szKeyExp);
Add('Key Condition: ' + MyidxDesc.szKeyCond);
Add('Case Insensitive: ' + BoolVal(MyidxDesc.bCaseInsensitive));
Add('iBlockSize: ' + IntToStr(MyidxDesc.iBlockSize));
Add('iRestrNum: ' + IntToStr(MyidxDesc.iRestrNum));
end;
end;