Thema: Delphi Problem mit CopyFileEx

Einzelnen Beitrag anzeigen

Paul0703

Registriert seit: 24. Sep 2008
Ort: Halle(Saale)
138 Beiträge
 
Delphi 7 Professional
 
#9

Re: Problem mit CopyFileEx

  Alt 27. Sep 2008, 21:14
Zitat von sx2008:
Hier eine kleine Verbesserung: der Parameter lpData wird benützt um sich vom Formular unabhängig zu machen.
Delphi-Quellcode:
function CopyFileProgress(TotalFileSize, TotalBytesTransferred, StreamSize,
  StreamBytesTransferred: LARGE_INTEGER; dwStreamNumber, dwCallbackReason,
  hSourceFile, hDestinationFile, lpData: DWORD): DWORD; stdcall;
var
  pb : TProgressBar;
begin
  pb := TProgressBar(lpdata); // <===
  Application.ProcessMessages;
  if CancelCopy then
  begin
    ShowMessage('Abbruch');
    result := PROGRESS_CANCEL;
    pb.Position := 0;
    Exit;
  end
  else
  Application.ProcessMessages;
  case dwCallbackReason of
    CALLBACK_CHUNK_FINISHED:
      begin
        pb.Position := TotalBytesTransferred.QuadPart;
        result := PROGRESS_CONTINUE;
      end;
    CALLBACK_STREAM_SWITCH:
      begin
        pb.Max := TotalFileSize.QuadPart;
        result := PROGRESS_CONTINUE;
      end;
    end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  Cancel: PBOOL;
begin
  CancelCopy := False;
  Cancel := nil;
  CopyFileEx('C:\aaa.exe', 'D:\aaa.exe',
    @CopyFileProgress, Pointer(ProgressBar1), Cancel, 0);
  ProgressBar1.Position := 0;
end;
Danke für den Tip!
  Mit Zitat antworten Zitat