即使数据库表存在,Delphi TTable.Exists 在 Paradox 表上也会失败

发布于 2024-11-11 19:05:10 字数 1020 浏览 6 评论 0原文

当我从头开始创建表对象 (Table1) 并将 TableName 属性分配给磁盘上的现有表时,Table1.Exist 函数失败。我使用的是 Delphi2010,它是一个 Paradox 7 表。

filename := ZipMaster1.DirEntry[i].FileName;
if Pos('.DB', UpperCase(filename)) > 0 then
begin
  Table1 := TTable.Create(FormArchiveFileSelector);
  Table1.TableName := IncludeTrailingPathDelimiter(ExtractDir) + ExtractFileName(filename);
  if Table1.Exists then
    Table1.DeleteTable;
  Table1.Free;
end;

当我将 Table1.Exists 替换为 FileExists(Table1.TableName) 时,返回 true。有人对此有任何解释吗?

解决方案代码

遵循建议,下面是一些“正确”的示例代码:

filename := 'C:\Temp\tables\XXX_1.db';
Table1.DatabaseName := ExtractFilePath(filename);
Table1.Tablename := ExtractFileName(filename);
if Table1.Exists then MessageDlg('Exists', mtInformation, [mbOK], 0)
else MessageDlg('Missing', mtInformation, [mbOK], 0);

注意:即使将 Table1.Tablename 设置为完整路径和表名,同时正确设置 DatabaseName 也会导致 Exists 函数失败。 TableName 必须始终不带路径。

When I create a table object (Table1) from scratch and assign the TableName property to an existing table on disk, the Table1.Exist function fails. I'm using Delphi2010 and it is a Paradox 7 table.

filename := ZipMaster1.DirEntry[i].FileName;
if Pos('.DB', UpperCase(filename)) > 0 then
begin
  Table1 := TTable.Create(FormArchiveFileSelector);
  Table1.TableName := IncludeTrailingPathDelimiter(ExtractDir) + ExtractFileName(filename);
  if Table1.Exists then
    Table1.DeleteTable;
  Table1.Free;
end;

When I replace Table1.Exists with FileExists(Table1.TableName), this returns true. Does anyone have any explanantion for this?

Solution code

Followed suggestions, below is some 'correct' sample code:

filename := 'C:\Temp\tables\XXX_1.db';
Table1.DatabaseName := ExtractFilePath(filename);
Table1.Tablename := ExtractFileName(filename);
if Table1.Exists then MessageDlg('Exists', mtInformation, [mbOK], 0)
else MessageDlg('Missing', mtInformation, [mbOK], 0);

Note: Even setting Table1.Tablename to the full path and tablename while setting DatabaseName properly cause the Exists function to fail. TableName must be without the path, always.

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

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

发布评论

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

评论(1

听你说爱我 2024-11-18 19:05:10

您需要分别设置DatabaseName 和FileName。

Table1 := TTable.Create(whatever);
Table1.DatabaseName := ExtractDir;
Table1.TableName := ExtractFileName(filename);

(你真的应该远离 BDE 和 Paradox 文件(以及 TTable)。BDE 已经被弃用十多年了,并且可能不会在 Delphi 的未来版本中发布。最新版本的 Delphi 存在严重问题Windows 也是如此。)

You need to separately set the DatabaseName and FileName.

Table1 := TTable.Create(whatever);
Table1.DatabaseName := ExtractDir;
Table1.TableName := ExtractFileName(filename);

(You should really get away from the BDE and Paradox files (as well as TTable). The BDE has been deprecated for more than a decade now, and may not ship in future versions of Delphi. There are serious issues with the latest versions of Windows as well.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文