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
| procedure TFFicheDocExterneDOC.sBtnValiderClick(Sender: TObject);
const
TailleBloc = 1024;
var
pBuffer: Pointer;
TailleSource, i, j: integer;
DossierDestination, FileDestination: String;
Source, Destination: TFileStream;
begin
// ...
DossierDestination := IncludeTrailingPathDelimiter(Logiciel.UNC)+
IncludeTrailingPathDelimiter(Logiciel.DossierDeTravail)+
IncludeTrailingPathDelimiter(Logiciel.DossierDOC);
FPauseFileStream := TFPauseFileStream.Create(Self);
Screen.Cursor := crSQLWait;
Try
FPauseFileStream.Caption := 'Copie de fichier(s)...';
FPauseFileStream.sLabelDe.Caption := '';
FPauseFileStream.sLabelVers.Caption := DossierDestination;
FPauseFileStream.sGaugeLesFichiers.Progress := 0;
FPauseFileStream.sGaugeLesFichiers.MaxValue := sOpenDialog1.Files.Count - 1;
FPauseFileStream.slabelLesFichiers.Caption := 'Fichier(s) '+inttostr(FPauseFileStream.sGaugeLesFichiers.Progress)+'/'+inttostr(FPauseFileStream.sGaugeLesFichiers.MaxValue);
FPauseFileStream.sGaugeLeFichier.Progress := 0;
FPauseFileStream.Show;
FPauseFileStream.Refresh;
for i := 0 to sOpenDialog1.Files.Count - 1 do
begin
Source := TFileStream.Create(sOpenDialog1.Files[i],fmOpenRead);
Try
TailleSource:= Source.Size;
FPauseFileStream.sLabelDe.Caption := ExtractFilePath(sOpenDialog1.Files[i]);
FPauseFileStream.sGaugeLeFichier.Progress := 0;
FPauseFileStream.sGaugeLefichier.MaxValue := TailleSource;
FPauseFileStream.slabelLeFichier.Caption := sOpenDialog1.Files[i];
FPauseFileStream.Refresh;
Source.Position := 0;
FileDestination := DossierDestination + ExtractFileName(sOpenDialog1.Files[i]);
Destination := TFileStream.Create(FileDestination,fmOpenWrite or fmCreate);
Try
GetMem(pBuffer, TailleBloc);
j:= 1;
while j * TailleBloc <= TailleSource do
begin
Source.ReadBuffer(pBuffer^, TailleBloc);
Destination.WriteBuffer (pBuffer^, TailleBloc);
FPauseFileStream.sGaugeLeFichier.Progress := j * TailleBloc;
inc(j);
end;
Source.ReadBuffer(pBuffer^, TailleSource- (j-1)* TailleBloc);
Destination.WriteBuffer(pBuffer^, TailleSource- (j-1)* TailleBloc);
Finally
Destination.Free;
End;
Finally
Source.Free;
End;
FPauseFileStream.sGaugeLesFichiers.Progress := FPauseFileStream.sGaugeLesFichiers.Progress + 1;
FPauseFileStream.slabelLesFichiers.Caption := 'Fichier(s) '+inttostr(FPauseFileStream.sGaugeLesFichiers.Progress)+'/'+inttostr(FPauseFileStream.sGaugeLesFichiers.MaxValue);
end;
Finally
FreeMem(pBuffer, TailleBloc);
Screen.Cursor := crDefault;
FPauseFileStream.Release;
End;
ModalResult := mrOk;
end; |
Partager