这个问题我前几天回答过,我把我程序中的一段代码再贴一遍
procedure TMainForm.N11Click(Sender: TObject);
var
mdbpath:string;
begin
mdbpath:=extractfilepath(application.exename);
daodatabase1.connected:=false;
if __DBEngine35 = nil then CreateEngine (Dao35, '');
__DBEngine35.CompactDatabase (mdbpath+'gz.mdb',mdbpath+'gz1.mdb' , '', 0, '');
deletefile('gz.mdb');
copyfile(pchar(mdbpath+'gz1.mdb'),Pchar(mdbpath+'gz.mdb'),false);
deletefile('gz1.mdb');
daodatabase1.databasename:='gz.mdb';
daodatabase1.connected:=true;
daotable1.open;
end;