Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi CopyFileEx kopiert nicht (https://www.delphipraxis.net/164757-copyfileex-kopiert-nicht.html)

Luckie 28. Nov 2011 20:19

AW: CopyFileEx kopiert nicht
 
Kommt erst der Fehler mit dem Fehlercode 32 noch? Dann könnte 1235 bedeuten dass die Anforderung an die Callback-Funktion abgebrochen wird, was logisch wäre, da die Datei nicht kopiert werden kann.

Destroxi 28. Nov 2011 20:25

AW: CopyFileEx kopiert nicht
 
Ne 32 kommt nicht mehr, 1235 auch nicht mehr, allerdings kommt ein "Access violation" Error wenn ich @PProgressRoutine als 3. Parameter rein nehme.
Was ist denn da falsch? Finde nichts...
Delphi-Quellcode:
function PProgressRoutine(TotalFileSize,
                            TotalBytesTransferred,
                            StreamSize,
                            StreamBytesTransferred: LARGE_INTEGER;
                            dwStreamNumber,
                            dwCallbackReason: DWORD;
                            hSourceFile,
                            hDestinationFile: THandle;
                            lpData: Pointer): DWORD; stdcall;
var
 Prozent: Integer;
begin
  try
   Prozent := Round(TLMDBiProgressBar(lpData).DarkValue / TLMDBiProgressBar(lpData).Scale * 100);
  except
   Prozent := 0;
  end;
  MainForm.laGesamt.Caption := 'Gesamt-Fortschritt ('+IntToStr(Prozent)+'%):';
  if dwCallbackReason = CALLBACK_STREAM_SWITCH then
    TLMDBiProgressBar(lpData).Scale := TotalFileSize.QuadPart;

  TLMDBiProgressBar(lpData).DarkValue := TotalBytesTransferred.QuadPart;
  Application.ProcessMessages;
  Result := PROGRESS_CONTINUE;
end;
Mfg, Destroxi

Bummi 28. Nov 2011 20:44

AW: CopyFileEx kopiert nicht
 
wenn ich FCancelled wie bei Dir als Prozedurvariable verwende kopiert er genau eine Datei, auch wenn ich die Variable bei jedem Loop setze. Lege ich sie außerhalb an läuft er durch.
Meine PProgressRoutine ist nur noch ein Rumpf von Deiner ....

Irgendwas ist das am Rutschen .....

Destroxi 28. Nov 2011 20:49

AW: CopyFileEx kopiert nicht
 
Liste der Anhänge anzeigen (Anzahl: 2)
Mein Problem ist ja dass ich nen Access Violation Error bekomme wenn ich statt
Code:
If not CopyFileEx(PChar(Files[y]), PChar(ExtractFilePath(aDestPath)+ExtractFileName(Files[y])),
    nil, nil, FCancelled, 0) then
dies schreibe:
Delphi-Quellcode:
If not CopyFileEx(PChar(Files[y]), PChar(ExtractFilePath(aDestPath)+ExtractFileName(Files[y])),
    @PProgressRoutine, nil, FCancelled, 0) then
Ansonsten werd ich das mal probieren wenn kein Access Violation error mehr kommt ;)

Edit: Ja klar, "lpData" muss gesetzt werden; gesagt - getan - und schon klappts ;)

Danke!!!

Edit²: Für alle die die funktionierende Lösung wollen:
Delphi-Quellcode:
function PProgressRoutine(TotalFileSize,
                            TotalBytesTransferred,
                            StreamSize,
                            StreamBytesTransferred: LARGE_INTEGER;
                            dwStreamNumber,
                            dwCallbackReason: DWORD;
                            hSourceFile,
                            hDestinationFile: THandle;
                            lpData: Pointer): DWORD; stdcall;
begin
  if dwCallbackReason = CALLBACK_STREAM_SWITCH then
    TLMDBiProgressBar(lpData).Scale := TotalFileSize.QuadPart;

  TLMDBiProgressBar(lpData).DarkValue := TotalBytesTransferred.QuadPart;
  Application.ProcessMessages;
  Result := PROGRESS_CONTINUE;
end;

procedure ListCopyProgress(const Files: TStrings; aDestPath: String; TotalProgressBar, CurrentProgressBar: TLMDBiProgressBar);
var
  x, y, Prozent: integer;
begin
  x:=Files.Count;
  TotalProgressBar.MinValue := 0;
  TotalProgressBar.Scale := x;
  for y:=0 to x-1 do
  begin
   MainForm.laAktiveDatei.Caption := 'Aktuelle Datei: '+ExtractFileName(Files[y]);
   try
   Prozent := Round(TotalProgressBar.DarkValue / TotalProgressBar.Scale * 100);
  except
   Prozent := 0;
  end;
  MainForm.laGesamt.Caption := 'Gesamt-Fortschritt ('+IntToStr(Prozent)+'%):';
   If not CopyFileEx(PChar(Files[y]), PChar(ExtractFilePath(aDestPath)+ExtractFileName(Files[y])),
    @PProgressRoutine, MainForm.pbAktiveDatei, FCancelled, 0) then
   begin
    ShowMessage('File['+IntToStr(y)+']: '+Files[y]+#10+
                'DestFile['+IntToStr(y)+']: '+ExtractFilePath(aDestPath)+ExtractFileName(Files[y])+#10+
                'Error: '+IntToStr(GetLastError));
   end;
     TotalProgressBar.DarkValue := y+1;
     TotalProgressBar.Update;
     CurrentProgressBar.Update;
 end;
 MainForm.laAktiveDatei.Caption := 'Aktuelle Datei: Keine';
 MainForm.laGesamt.Caption := 'Gesamt-Fortschritt (100%):';
end;
Und anwenden mit bsp:
Delphi-Quellcode:
ListCopyProgress(DateienStringList, 'C:\ZielPfad\', ProgressBarAlleDateien, ProgressBarAktiveDatei);
Und für alle, die es immer noch nicht verstehen gibts im Anhang nen kleines Beispiel-Programm mit Quellcode ;)
PS: Um dieses Programm nutzen zu können benötigt ihr die LMD Komponenten!

Mfg, Destroxi

himitsu 28. Nov 2011 21:09

AW: CopyFileEx kopiert nicht
 
Zitat:

Zitat von Destroxi (Beitrag 1138291)
Jetzt meine Frage: Warum funktioniert das nicht (es kopiert die Dateien einfach nicht und liefert immer "False" zurück)?

Meine Antwort: Schau mal, was noch zum Result (return value) im MSDN steht. :roll:

MSDN-Library durchsuchenCopyFileEx

Destroxi 28. Nov 2011 21:23

AW: CopyFileEx kopiert nicht
 
Zitat:

Edit: Ja klar, "lpData" muss gesetzt werden; gesagt - getan - und schon klappts

Danke!!!
Es klappt bereits ;)

Aber Danke :D

Mfg, Destroxi

Benmik 2. Jun 2014 21:50

AW: CopyFileEx kopiert nicht
 
Nur für den Fall der Fälle - der Beitrag ist ja noch nicht sooo alt und manch einer kommt über Google und kopiert die Routinen hier raus:

Destroxi hat FCancelled als Boolean definiert. Da kann man in eine Falle tappen:

FCancelled als BOOL festlegen

himitsu 2. Jun 2014 23:21

AW: CopyFileEx kopiert nicht
 
Bei der Variable meinst du bestimmt BOOL oder LongBool (anstatt PBOOL). :D

Benmik 2. Jun 2014 23:28

AW: CopyFileEx kopiert nicht
 
So isses ...

Und wenn du mir jetzt noch sagst, warum MainForm.pbAktiveDatei nicht als @MainForm.pbAktiveDatei übergeben wird, obwohl doch ein Pointer gefordert ist...

himitsu 3. Jun 2014 00:26

AW: CopyFileEx kopiert nicht
 
Weil ein Objektzeiger im Prinzip schon ein Pointer ist.


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:13 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz