在Delphi for Win32中,如何在没有BDE的情况下以本机方式读取和写入dbf文件?我知道网上有一些组件,但我从未使用过任何组件,所以我不知道如何选择(如果有的话).
RRU*_*RUZ 17
您可以使用ADO访问DBF文件
查看示例代码(使用TAdoConnection和TAdoDataSet组件).
var
dbf_folder : string;
begin
dbf_folder:='c:\bdd';//set your dbf folder location here
ADOConnection1.LoginPrompt:=false;
ADOConnection1.ConnectionString:=Format('Provider=Microsoft.JET.OLEDB.4.0;Data Source=%s;Extended Properties=dBase IV;',[dbf_folder]);
try
ADOConnection1.Connected:=True;
ADODataSet1.CommandText:='Select * from file.dbf'; //make your SQL query using the name of the dbf file
ADODataSet1.Open;
while not ADODataSet1.eof do
begin
//do your stuff here
//ADODataSet1.FieldByName('').AsString
ADODataSet1.Next;
end;
except
on E : Exception do
ShowMessage(E.Message);
end;
end;
Run Code Online (Sandbox Code Playgroud)