Einzelnen Beitrag anzeigen

gee21

Registriert seit: 3. Jan 2013
199 Beiträge
 
Delphi 10.4 Sydney
 
#1

Kopieren mit TProgressbar Ausserhalb des gültigen bereiches

  Alt 21. Feb 2013, 18:08
Hallo alle zusammen.

Habe im netz (Bei Torry)
Den folgenden Code gefunden und minimal angepasst. Egentlich funktioniert auch alles. (Dateien, respektive Ordner Inhalt kopieren)
Aber je nach Dateigrösse die ich verwende zum kopieren, erhalte ich zum Teil (nicht immer) die Fehlermeldung:

"Eigenschaft TProgressbar ausserhalb der zulässigen Bereiches."

ich vermute das der Max Wert der Progressbar je nach Dateigrösse zu gross ist. Daher versuchte ich einfach den Wert zu dividieren durch 100
Aber irgendwie klappte auch dass nicht und die Fehlermeldung kommt weiterhinn


Delphi-Quellcode:
type
   TCallBack = procedure(Position, Size: Longint); { export; }

procedure FastFileCopy(const InFileName, OutFileName: string;
   CallBack: TCallBack);

implementation

uses Optionen, Unit3, Unit5, Unit6, Unit7, Unit8, uFTPServer;

{$R *.dfm}



procedure TForm1.WMSysCommand;
begin
if (Msg.CmdType = SC_MAXIMIZE) then
button6.Click ;
DefaultHandler(Msg) ;
if form1.WindowState=wsmaximized then form1.WindowState:=wsnormal;
end;


procedure FastFileCopyCallBack(Position, Size: longint);
begin



   Form1.ProgressBar1.Max := Size;
   Form1.ProgressBar1.Position := Position;

// BRINGT nichts
// Form1.ProgressBar1.Max := Size div 100;
// Form1.ProgressBar1.Position := Position div 100;


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
   if (InFileName <> OutFileName) then
   begin
     buffer := nil;
     Assign(infile, InFileName);
     Reset(infile, 1);
     try
       SizeFile := FileSize(infile);
       Assign(outfile, OutFileName);
       Rewrite(outfile, 1);
       try
         SizeDone := 0;
         New(Buffer);
         repeat
         application.ProcessMessages;
           BlockRead(infile, Buffer^, BufSize, Size);
           Inc(SizeDone, Size);
           CallBack(SizeDone, SizeFile);
           BlockWrite(outfile, Buffer^, Size)
         until Size < BufSize;
         FileSetDate(TFileRec(outfile).Handle,
         FileGetDate(TFileRec(infile).Handle));
       finally
         if Buffer <> nil then
           Dispose(Buffer);
         CloseFile(outfile)
       end;
     finally
       CloseFile(infile);
     end;
   end
   else
     raise EInOutError.Create('File cannot be copied onto itself')
end; {FastFileCopy}


Aufrufen tu ich es dann so:

Delphi-Quellcode:
 if directoryexists(form2.Edit2.Text+'\'+form1.ListBox1MAINLISTE.Items[form1.ListBox1MAINLISTE.ItemIndex])=false then forcedirectories(form2.Edit2.Text+'\'+form1.ListBox1MAINLISTE.Items[form1.ListBox1MAINLISTE.ItemIndex]);

repeat
application.ProcessMessages;

if fileexists(form1.FileListBox1.Items[0]) then begin
FastFileCopy(form1.FileListBox1.Items[0], form2.Edit2.Text+'\'+form1.ListBox1MAINLISTE.Items[form1.ListBox1MAINLISTE.ItemIndex]+'\'+form1.FileListBox1.Items[0], @FastFileCopyCallBack);
application.ProcessMessages;
end;
if form1.FileListBox1.Items.Count>0 then form1.FileListBox1.Items.Delete(0);

until form1.FileListBox1.Items.Count<1;
PlaySound(PChar(ExtractFilePath(Application.Exename)+'\Sounds\copy.wav'),0,SND_ASYNC);

Könnt ihr mir sagen wo der Fehler passiert? Respektive wie man ihn einfach lösen könnte?

Danke & Gruess
Robert
  Mit Zitat antworten Zitat