uses
DB, DBTables, DbiProcs, DbiErrs, DbiTypes;
procedure CopyTable(FromDir, SrcTblName, ToDir, DestTblName:
String);
var
DBHandle: HDBIDB;
ResultCode: DBIResult;
Src, Dest, Err: Array[0..255] of Char;
SrcTbl, DestTbl: TTable;
begin
SrcTbl := TTable.Create(Application);
DestTbl := TTable.Create(Application);
try
SrcTbl.DatabaseName := FromDir;
SrcTbl.TableName := SrcTblName;
SrcTbl.Open;
DBHandle := SrcTbl.DBHandle;
SrcTbl.Close;
ResultCode := DbiCopyTable(DBHandle,false,
StrPCopy(Src,FromDir + '\' + SrcTblName), nil,
StrPCopy(Dest,ToDir + '\' + DestTblName));
if ResultCode <> DBIERR_NONE then
begin
DbiGetErrorString(ResultCode,Err);
raise EDatabaseError.Create('While copying ' +
FromDir + '\' + SrcTblName + ' to ' +
ToDir + '\' + DestTblName + ', the '
+ ' database engine generated the error '''
+ StrPas(Err) + '''');
end;
finally
SrcTbl.Free;
DestTbl.Free;
end;
end;
|