如何在Delphi 4中生成MDX,NDX,CDX索引文件?(50分)

  • 主题发起人 主题发起人 bobyin
  • 开始时间 开始时间
B

bobyin

Unregistered / Unconfirmed
GUEST, unregistred user!
我想自己编一个有关DBF的小程序,请问如何生成和重新索引CDX,MDX,NDX文件
 
mdx是dbase数据库的索引
cdx是foxpro的索引
ndx是foxbase的索引
delphi只能生成mdx, 但能调用其它的索引.
通过odbc生成其它的吧
 
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;
-------------------------------------------------------------------
 
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;
-------------------------------------------------------------------
 
太麻烦, 还不如用一句sql来生成mdx
CREATE INDEX index_name ON table_name (column [, column ...]);
var
query1: TQuery;
begin
query1:=tquery.create(nil);
query1.sql.text:='CREATE INDEX "TEMPINDX" ON "TEMP.DBF" (FNAME)';
query1.ExecuteSQL;
query1.free;
end;

:)
 
Delphi的BDE对于xbase,其效果是很不如人意的。在下试过如果ZAP一个数据库的话,
CDX索引居然坏掉,另外共享机制与XBASE,Foxpro等是不兼容的,还有很多怪事,
就不一一列举了。
如果您想操作xbase类型的数据库,建议您使用第三方控件,可以替代BDE的呵!最出
名的有两个,分别是codebase6.x和Halcyon(翠鸟).
codebase很贵,Halcyon可到其主页去:http://www.grifsolu.com 下载Halcyon5
试用版(无源码),应该可以解决您的问题。
 
多人接受答案了。
 
后退
顶部