即使数据库表存在,Delphi TTable.Exists 在 Paradox 表上也会失败
当我从头开始创建表对象 (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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要分别设置DatabaseName 和FileName。
(你真的应该远离 BDE 和 Paradox 文件(以及 TTable)。BDE 已经被弃用十多年了,并且可能不会在 Delphi 的未来版本中发布。最新版本的 Delphi 存在严重问题Windows 也是如此。)
You need to separately set the DatabaseName and 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.)