DBase table notes:
An .MDX index is a "maintained index". This is the only type of
dBase index anyone should ever use! Some types of xBase indicies are
Clipper or FoxBase specific. Non-maintained indicies have a self-
defeating purpose.
Q: How can I programatically create an index for a dBase table?
A: Below is the code for OnClick method of a button that creates
an index on a dBase table:
procedure TForm1.Button1Click(Sender: TObject);
var
bActive, bExclusive: Boolean ;
begin
{ save original open and active status }
bActive := Table1.Active;
bExclusive := Table1.Exclusive;
Table1.IndexDefs.Update;
with Table1 do
begin
Close;
{ dBASE table needs to be open in exclusive mode in order to
create an index! This can fail if anyone is using the table!
}
Exclusive := TRUE;
Open;
{ Make sure you have a data field of specified name }
{ Question - I though the first index is number 0?!!! }
if Table1.FieldDefs.IndexOf('FNAME') <> 0 then { is the fldname
valid? }
Table1.AddIndex('FNAME', 'FNAME', [] );
Close;
Exclusive := bExclusive; { turn off exclusive mode }
Active := bActive; { open table again }
end;
-------------------------------------------------------------------