如何以原生方式读写 dbf?

发布于 2024-09-24 14:54:34 字数 99 浏览 6 评论 0原文

在Delphi for Win32中,如何在没有BDE的情况下以本机方式读写dbf文件?我知道网络上有一些可用的组件,但我从未使用过其中任何一个,所以我不知道该选择哪个(如果有的话)。

In Delphi for Win32, how to read and write a dbf file in a native way, without the BDE? I know there are some components available in the web, but I have never used any of them, so I don't know which to choose (if any).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

み零 2024-10-01 14:54:34

您可以使用 ADO 访问 DBF 文件,

请参阅示例代码(使用 TAdoConnection< /code>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;

You can use ADO to access a DBF File

See ths sample code (using an TAdoConnection and TAdoDataSet components).

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;
无法回应 2024-10-01 14:54:34

当我还在处理 DBF 文件(一些旧版应用程序)时,我使用了 TDBF 。我仍然使用它来维护这些应用程序。它是免费的,有很多功能并且运行良好。

I used TDBF back when I was still working with DBF files (some legacy apps). I still use it for maintainance of those apps here and there. It is free, has a lot of features and works good.

关于从前 2024-10-01 14:54:34

在开始使用 Firebird 之前,我使用 Software Science 中的 Topaz 已有多年。它始终是一个优秀的库,有很棒的手册和良好的技术支持。它支持索引,甚至有内存选项。我认为这将是一个不错的选择。

I used Topaz from Software Science for many years before I got started with Firebird. It was always an excellent library, had a terrific manual and good technical support. It supports indexes and even has an in-memory option. I think it would be a good choice.

云醉月微眠 2024-10-01 14:54:34

ADO 对我不起作用,但我设法使用 BDE 打开我的 dbf 文件:

从数据访问(或 BDE,取决于您的 Delphi 版本)部分,我放置了 TDataBase 和 TTable 组件(如果需要,您可以使用 TQuery )。

通过双击 TDataBase 组件,我打开了设置对话框。用“db_name”填充名称字段(名称是任意的),驱动程序名称=“STANDARD”,参数字段:“PATH=C:\Path\To\DBF_FILES\”。
然后我设置 Connected=True。

然后在 TTable 组件中我设置 DatabaseName = 'db_name' - 我在 TDataBase 组件中设置的那个。并将 TableName 属性设置为位于指定文件夹中的“DB_FILE.dbf”。
有效 = 真。

你知道下一步该做什么

ADO didn't work for me but I managed to open my dbf file using BDE:

From a Data Access (or BDE, depends on your version of Delphi) section I put a TDataBase and, TTable components (you can use TQuery if you want).

By doubleclick on TDataBase component I opened the setup dialog. Filled the Name field with 'db_name' (the name is arbitrary), driver name = 'STANDARD', Parameters field: 'PATH=C:\Path\To\DBF_FILES\'.
Then I set Connected=True.

Then in TTable component I set DatabaseName = 'db_name' - the one I set in TDataBase component. And TableName property set 'DB_FILE.dbf' which was located in the specified folder.
Active = True.

You know what to do next

若沐 2024-10-01 14:54:34

如果不需要索引,读取 DBF 文件并不难。格式非常简单。后面是固定大小寄存器的标头。每个寄存器中都有一个标志来指示它是否被删除。我建议寻找一个可以满足您需求的组件。您可以在 Torry 的 Delphi 页面中找到一些内容。

It is not hard to read a DBF file if you don't need indexes. The format is pretty straightforward. A header followed for fixed sized registers. There is a flag in each register which indicates if it is deleted or not. I suggest looking for a component which does what you want. You can find some in Torry's Delphi pages.

我的影子我的梦 2024-10-01 14:54:34

你可以尝试这个简单的方法

Query1.Close;
Query1.DatabaseName := ExtractFilePath(Application.ExeName); //path to your file
Query1.SQL.Text := 'SELECT * FROM Test_123.dbf';
Query1.Open;

You can try this simple way

Query1.Close;
Query1.DatabaseName := ExtractFilePath(Application.ExeName); //path to your file
Query1.SQL.Text := 'SELECT * FROM Test_123.dbf';
Query1.Open;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文