Einzelnen Beitrag anzeigen

Volker Z.

Registriert seit: 3. Dez 2012
Ort: Augsburg, Bayern, Süddeutschland
419 Beiträge
 
Delphi XE4 Ultimate
 
#7

AW: Kopieren mit TProgressbar Ausserhalb des gültigen bereiches

  Alt 21. Feb 2013, 19:55
Hi gee21,

versuch mal folgendes:
Delphi-Quellcode:
procedure FastFileCopyCallBack(Position, Size: longint);
begin
  Form1.ProgressBar1.Max := Size;
  Form1.ProgressBar1.Position := Position;
  Form1.ProgressBar1.Update
end;

procedure FastFileCopy(const InFileName, OutFileName: string; CallBack: TCallBack);
const
   BufSize = 3 * 4 * 4096; { 48Kbytes gives me the best results }
type
   PBuffer = ^TBuffer;
   TBuffer = array[1..BufSize] of Byte;
var
   Size: DWORD;
   Buffer: PBuffer;
   infile, outfile: file;
   SizeDone, SizeFile: LongInt;
begin
  buffer := nil;
  if (InFileName <> OutFileName) then
    try
      try
        AssignFile(infile, InFileName);
        Reset(infile, 1);
        AssignFile(outfile, OutFileName);
        Rewrite(outfile, 1);

        SizeDone := 0;
        SizeFile := FileSize(infile);

        Callback (0, SizeFile);

        New(Buffer);
        repeat
          BlockRead(infile, Buffer^, BufSize, Size);
          Inc(SizeDone, Size);
          BlockWrite(outfile, Buffer^, Size);

          Callback (SizeDone, SizeFile)
        until Size < BufSize;

        FileSetDate(TFileRec(outfile).Handle, FileGetDate(TFileRec(infile).Handle));
      except
        // Exception behandeln
      end
    finally
      if Buffer <> nil then
        Dispose(Buffer);
      CloseFile(outfile);
      CloseFile(infile)
    end
  else
    raise EInOutError.Create('File cannot be copied onto itself')
end;
Sollte funktionieren.

Grüße in die Schweiz
Volker Zeller
  Mit Zitat antworten Zitat