程序里面的代码,已经贴过,重新贴一次吧,全做灌水了。使用ADO压缩
function TFrm_Export_Show.Compact_DB(l_Dest_DBName: String; l_Password: String): Boolean;
var
Dest_DB_Connection: OleVariant;
l_Source_Con_Str, l_Dest_Con_Str: String;
begin
DM_Pub.Acon_Export.Close;
if FileExists(l_Dest_DBName) = True then
if DeleteFile(pChar(l_Dest_DBName)) = False then
begin
Application.MessageBox(pchar('覆盖文件' + l_Dest_DBName + '出错!可能文件正在被使用!'), '提示', 48 + mb_ok);
Result := False;
Exit;
end;
try
Dest_DB_Connection := CreateOleObject('JRO.JetEngine');
except
if Application.MessageBox('创建JRO.JetEngine失败!可能是当前所安装的ADO版本不同!压缩数据库失败!是否将没有压缩的文件导出?', '询问', 32 + mb_ok) = MrYes then
begin
Result := Export_DB_File(l_Dest_DBName);
Exit;
end
else
begin
Result := False;
Exit;
end;
end;
l_Source_Con_Str :=
'Data Source=' + VG_APP_PATH + 'JWC_Export.MDB' + ';' +
'Jet OLEDB
atabase Password="' + VG_DB_PASS + '"';
l_Dest_Con_Str :=
'Data Source=' + l_Dest_DBName + ';' +
'Jet OLEDB
atabase Password="' + l_Password + '"';
try
OleCheck(Dest_DB_Connection.CompactDatabase(l_Source_Con_Str, l_Dest_Con_Str));
Result := True;
except
if Application.MessageBox('压缩导出文件失败!是否将未压缩的文件导出?', '询问', 32 + mb_YesNo) = mrYes then
Result := Export_DB_File(l_Dest_DBName)
else
Result := False;
end;
end;