1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
procedure TForm1.CopyBase;
var
AParams: TStringList;
sTable, sDirTable: string;
AA, MM, JJ: word;
begin
with dataModule do begin
TRY
// récup Dir de la table à copier
AParams := TStringList.Create;
Session.GetAliasParams(tableACopier.DataBaseName, AParams);
sDirTable := Copy(AParams.Strings[0], 6, 255);
FINALLY
AParams.Free;
END;
// crée un nom de table indexé sur la date
DecodeDate(Date, AA, MM, JJ);
if AA > 2000 then
sTable := 'TableSave ' + Copy(IntToStr(AA), 3, 2)
else
sTable := 'TableSave ' + IntToStr(AA);
if MM < 10 then
sTable := sTable + '0' + IntToStr(MM)
else
sTable := sTable + IntToStr(MM);
if JJ < 10 then
sTable := sTable + '0' + IntToStr(JJ)
else
sTable := sTable + IntToStr(JJ);
if FileExists(sDirTable + sTable) then
Exit; // on n'écrase pas l'ancienne
if not bCreateTableLocale(sDirMemTable, sTable) then
Exit; // création impossible
TRY
table1.Close;
table1.Filtered := false;
bmCopyLocale.Execute;
EXCEPT
Exit;
END;
end; // with
end;
function TfrmTable.bCreateTableLocale(sDirTable, sTable: string): boolean;
begin
Result := false;
with dataModule.tableSave do begin
Close;
DatabaseName := sDirTable;
TableName := sTable;
if FileExists(sDirTable + '\' + sTable) then begin
TRY
DeleteTable;
EXCEPT
TRY
EmptyTable;
EXCEPT
on E:EDatabaseError do begin
msg('Impossible de créer la table de sauvegarde !');
Exit;
end;
END;
END;
end;
// crée la table locale
FieldDefs.Clear;
FieldDefs.Add('Nom',ftString,20,False);
...
TRY
CreateTable;
IndexDefs.Clear;
AddIndex('', 'Nom', [ixPrimary,ixUnique]);
EXCEPT
on E:EDatabaseError do
Exit;
END;
Result := true;
end; // with
end; |
Partager