|
<< Click to Display Table of Contents >> Delphi Examples: DbiAddIndex |
![]() ![]()
|
Also see TTable.AddIndex in the Delphi online help. TTable.AddIndex will usually handle most of your indexing needs.
Example 1: Add an index to a Paradox 4.0 or 5.0 version table:
This is a primary index. This example uses the following input:
fDbiAddIndex1(Table1);
procedure fDbiAddIndex1(Tbl: TTable);
var
NewIndex: IDXDesc;
begin
if not Tbl.Exclusive then
raise EDatabaseError.Create('TTable.Exclusive must be set to ' +
'true in order to add an index to the table');
with NewIndex do begin
iIndexId:= 0;
bPrimary:= True;
bUnique:= True;
bDescending:= False;
bMaintained:= True;
bSubset:= False;
bExpIdx:= False;
iFldsInKey:= 1;
aiKeyFld[0]:= 1;
bCaseInsensitive:= False;
end;
Check(DbiAddIndex(Tbl.dbhandle, Tbl.handle, PChar(Tbl.TableName), szParadox, NewIndex, nil));
end;
Example 2: Add an index to a Paradox 4.0 or 5.0 version table.
This is a case insensitive, secondary, maintained index. This example uses the following input:
fDbiAddIndex2(Table1);
The procedure is defined as:
procedure fDbiAddIndex2(Tbl: TTable);
var
NewIndex: IDXDesc;
begin
if not Tbl.Exclusive then
raise EDatabaseError.Create
('TTable.Exclusive must be set to true in order to ' +
'add an index to the table');
with NewIndex do begin
szName:= 'NewIndex';
iIndexId:= 0;
bPrimary:= False;
bUnique:= False;
bDescending:= False;
bMaintained:= True;
bSubset:= False;
bExpIdx:= False;
iFldsInKey:= 1;
aiKeyFld[0]:= 2;
bCaseInsensitive:= True;
end;
Check(DbiAddIndex(Tbl.dbhandle, Tbl.handle, PChar(Tbl.TableName), szParadox, NewIndex, nil));
end;
Example 3: Add an index to a Paradox 7.0 version table.
This is a secondary unique / descending index. This example uses the following input:
fDbiAddIndex3(Table1);
The procedure is defined as:
procedure fDbiAddIndex3(Tbl: TTable);
var
NewIndex: IDXDesc;
begin
if not Tbl.Exclusive then
raise EDatabaseError.Create
('TTable.Exclusive must be set to true in order to ' +
'add an index to the table');
with NewIndex do begin
szName := 'NewIndex';
iIndexId := 0;
bPrimary := False;
bUnique := TRUE;
bDescending := True;
bMaintained := True;
bSubset := False;
bExpIdx := False;
iFldsInKey := 1;
aiKeyFld[0]:= 2;
bCaseInsensitive := True;
end;
Check(DbiAddIndex(Tbl.dbhandle, Tbl.handle, PChar(Tbl.TableName), szParadox, NewIndex, nil));
end;
Example 4: Add an index to a dBASE for Windows version table.
This example uses the following input:
fDbiAddIndex4(Table1);
The procedure is defined as:
procedure fDbiAddIndex4(Tbl: TTable);
var
NewIndex: IDXDesc;
begin
with NewIndex do begin
szTagName := 'NewIndex1';
bPrimary := False;
bUnique := False;
bDescending := False;
bMaintained := True;
bSubset := False;
bExpIdx := False;
iFldsInKey := 1;
aiKeyFld[0] := 2;
szKeyExp := ''; // Although this is not an Expression index,
szKeyCond := ''; // szKeyExp and szKeyCond must be set blank
bCaseInsensitive := False;
iBlockSize := 0;
end;
Check(DbiAddIndex(Tbl.dbhandle, Tbl.handle, PChar(Tbl.TableName), szDBASE, NewIndex, nil));
end;
Example 5: Add an expression index to a dBASE for Windows version table.
This example uses the following input:
fDbiAddIndex5(Table1);
The procedure is defined as:
procedure fDbiAddIndex5(Tbl: TTable);
var
NewIndex: IDXDesc;
begin
NewIndex.szTagName := 'EXPINDEX';
NewIndex.bPrimary := False;
NewIndex.bUnique := False;
NewIndex.bDescending := False;
NewIndex.bMaintained := True;
NewIndex.bSubset := False;
NewIndex.bExpIdx := True;
NewIndex.iFldsInKey := 1;
NewIndex.aiKeyFld[0] := 2;
NewIndex.szKeyExp := 'UPPER(FIELD1) + UPPER(FIELD2)';
NewIndex.szKeyCond := '';
NewIndex.bCaseInsensitive := False;
NewIndex.iBlockSize := 0;
Check(DbiAddIndex(Tbl.dbhandle, Tbl.handle, PChar(Tbl.TableName),
szDBASE, NewIndex, nil));
end;