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.
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.)