#include "utilcls.h"
void CompactDatabase(String f1,String psw1, String f2,String psw2)
{
String Provider1="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ f1 + ";Jet OLEDB:Database Password=" + psw1;
String Provider2="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ f2 + ";Jet OLEDB:Database Password=" + psw2;
Variant Adoobj=Variant::CreateObject("JRO.JetEngine");
Adoobj.OleProcedure("CompactDatabase",Provider1,Provider2);
AdoObj.Clear( ); // 釋放 ADO對象
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String f1="yhecdagl1.mdb"; // 源庫1
String psw1="yhecdagl"; // 密碼1
String f2="yhecdagl2.mdb"; // 新目的庫2
String psw2="yhecdagl2"; // 新密碼2
String dir=ExtractFilePath(Application->ExeName);
if (FileExists(f2))
DeleteFile(f2);
CompactDatabase(dir+f1,psw1,dir+f2,psw2);
ShowMessage("Finished");
}