05-09-2015, 12:29 PM
كود :
procedure TForm5.Button3Click(Sender: TObject);
begin
DataModule1.ADOConnection1.Close;
if CompactAndRepair('E:\Projet\gestion commerciale\gestion commerciale\gestion commerciale\gestion commerciale.mdb','') then
ShowMessage('database compact successfully');
DataModule1.utilisateur.Open;
end;كود :
[align=left]function CompactAndRepair(DB, Password: string) : boolean;
const
sProvider = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database Password="%s"';
var
v: OLEvariant;
begin { CompactAndRepair }
Result := True;
try
v := CreateOLEObject('JRO.JetEngine');
try
v.CompactDatabase(Format(sProvider, [DB, Password]), Format(sProvider, [DB + 'E:\Projet\gestion commerciale\gestion commerciale\gestion commerciale\gestion commerciale.mdb', Password]));
if FileExists(DB + 'E:\Projet\gestion commerciale\gestion commerciale\gestion commerciale\gestion commerciale.mdb') then begin
DeleteFile(DB);
RenameFile(DB + 'E:\Projet\gestion commerciale\gestion commerciale\gestion commerciale\gestion commerciale.mdb', DB)
end;
finally
v := Unassigned
end; { try }
except
Result := False
end; { try }
end; { CompactAndRepair }[/align]إستعملت الكود التالي ولم يعمل معي؟

