本文整理自网络,侵删。
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 xe更改ttrayicon系统任务栏图标(无模糊)
Delphi sysutils.stringreplace - 替换
Delphi firedac 连接sql server一些要注意的地方
Delphi xe ttask.waitforall/waitforany 一不小心会造成内存泄露
更多相关阅读请进入《Delphi》频道 >>