本文整理自网络,侵删。
uses ComObj;
procedure CompactMdb( SourceMdbPath, SourceMdbPassword, TargetMdbPath, TargetMdbPassword: String);const SOURCE_PARAM = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database Password=%s'; TARGET_PARAM = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Engine Type=%d;Jet OLEDB:Database Password=%s'; ENGINE_TYPE = 5; //Jet OLEDB:Engine类型var Engine: OleVariant; SourceStr, TargetStr: String;begin SourceStr := Format(SOURCE_PARAM, [SourceMdbPath, SourceMdbPassword]); TargetStr := Format(TARGET_PARAM, [TargetMdbPath, ENGINE_TYPE, TargetMdbPassword]); Engine := ComObj.CreateOleObject('JRO.JetEngine'); Engine.CompactDatabase(SourceStr, TargetStr);end;
procedure TForm1.FormCreate(Sender: TObject);begin
CompactMdb('C:\mdb\old.mdb', 'pass1','C:\mdb\new.mdb', 'pass2');
end;
相关阅读 >>
Delphi winapi: getmodulefilename、getmodulehandle
Delphi indy 组件包里的 idhttp 组件使用 get 方法下载文件限速的方法
Delphi关于tjpegimage的使用(bmp\ jpg格式转换)
更多相关阅读请进入《Delphi》频道 >>