本文整理自网络,侵删。
现在,Delphi Firedac只需几行代码就可以更干净地执行这些功能。
在数据模块中,您需要删除FDMSAccessService组件并将驱动程序链接设置为FDPhysMSAccessDriverLink
数据库连接应该关闭。
应该设置数据库名称和路径。
仅在使用数据库密码时才需要设置数据库密码。
执行修复和压缩以完成任务。
function TfrmMainForm.CompactAndRepair(const DB: string): Boolean;
begin
Result := True;
DM.DataMod.FDConnection.Connected := False;
DM.DataMod.FDMSAccessService.Database := DB;
DM.DataMod.FDMSAccessService.Password := 'PASSWORD';
try
DM.DataMod.FDMSAccessService.Repair;
except
on E : Exception do
begin
ShowMessage('Exception message = '+E.Message);
Result := False;
end;
end;
try
DM.DataMod.FDMSAccessService.Compact;
except
on E : Exception do
begin
ShowMessage('Exception message = '+E.Message);
Result := False;
end;
end;
DM.DataMod.FDConnection.Connected := True;
end;
相关阅读 >>
Delphi webbrowser控件的documentcomplete和downloadcomplete的区别
Delphi 如何让 tgpimage 直接从流中加载图片?
Delphi 从listview组件中的选定行在数据库中删除
Delphi 2009 新增单元 character isletter、isupper、islower、isdigit、isnumber
更多相关阅读请进入《Delphi》频道 >>