![]() |
CopyFileEx und Codeoptimierung XE5
Moin zusammen,
ich benutze DelphiXE5. CopyFileEx funktioniert da nicht wenn ich Codeoptimierung aktiv habe. :shock: D.h. es kommt der Fehler "Die Anforderung wurde abgebrochen" Delphi-Bug oder gibts dafür eine andere Erklärung? Danke |
AW: CopyFileEx und Codeoptimierung XE5
Die irrsinnige Menge des von Dir geposteten Sourcecodes hat mich fast zur Verzweiflung getrieben :roll:
|
AW: CopyFileEx und Codeoptimierung XE5
Wozu sourcecode? Der ist ja kaum falsch wenn es ohne Optimierung funktioniert.
Ausserdem ist der älter, d.h. in 2006 gabs auch mit Optimierung keine Fehler.
Delphi-Quellcode:
[B]
function TFileCopier.DoFolderFiles( const ASourcePath, ATargetPath: string; const Op: TFolderOp): Int64; var StrName, MySearchPath, MyTargetPath, MySourcePath: string; FindRec: TSearchRec; i: Integer; Cancelled: Boolean; Attrs: integer; CopyIt: boolean; begin Result := 0; Cancelled := False; MyTargetPath := AddBackSlash(ATargetPath); MySourcePath := AddBackSlash(ASourcePath); MySearchPath := AddBackSlash(ASourcePath) + '*.*'; i := FindFirst(MySearchPath, 0 , FindRec); try while (i = 0) and (Result <> -1) do begin try case op of foCopy: begin StrName := MySourcePath + FindRec.Name; CopyIt:= CopyAll or (FindRec.Attr and faArchive = faArchive); if CopyIt then begin //Cancelled:= false; if CopyFileEx(PWideChar(StrName), PWideChar(MyTargetPath + FindRec.Name), @fCallBack, Pointer(fHandle), @Cancelled, 0) then begin Attrs := FileGetAttr(StrName); FileSetAttr(StrName, Attrs and not faArchive); inc(Result); inc(fCopyCount); TUtils.WriteLogFile(eData, StrName + ' saved to ' + MyTargetPath + FindRec.Name); Sleep(50); end else begin Result := -1; TUtils.WriteLogFile(eError, StrName + ' not saved' + #13#10 + SysErrorMessage (GetLastError)); end; end; end; foCount: begin Inc(Result); Inc(fFileCount); end; foSize: begin Result := Result + FindRec.Size; fFileSize := fFileSize + FindRec.Size; end; end; // case except Result := -1; end; i := FindNext(FindRec); end; finally FindClose(FindRec); end; end; [/B] |
AW: CopyFileEx und Codeoptimierung XE5
Diese Zuweisungen werden wegoptimiert, weil die Variable aus Sicht des Compilers später nicht mehr angesprochen wird:
Delphi-Quellcode:
Wenn Du das Flag später nochmal abfragst könnte es gehen.
Cancelled:= false;
|
AW: CopyFileEx und Codeoptimierung XE5
Die Zeile gehört eigentlich nicht rein, war nur um das zu finden.
Das setzt man auf true um während des kopierens abzubrechen. So weit kommt man aber erst garnicht. |
AW: CopyFileEx und Codeoptimierung XE5
Liegt der Fehler evtl. im Callback?
|
AW: CopyFileEx und Codeoptimierung XE5
Laut API-Dokumentation ist aber doch genau das der Grund wenn er mit
Delphi-Quellcode:
rausgeht.
ERROR_REQUEST_ABORTED
Der andere wäre, wenn dein
Delphi-Quellcode:
fCallBack
Delphi-Quellcode:
zurückgibt, aber über das Ding wissen wir nichts.
PROGRESS_STOP
|
AW: CopyFileEx und Codeoptimierung XE5
Nein, ohne callback(nil) das gleiche Problem.
Am Cancel liegt das nicht, das war vorher auch dort nicht drin, brauch ich auch nicht. Die Funktion wird sofort abgebrochen. Aber eben nur wenn Optimierung an ist. pbCancel [in, optional] If this flag is set to TRUE during the copy operation, the operation is canceled. Otherwise, the copy operation will continue to completion. Callback sendet nur Messages, aber wie gesagt ohne Callback gehts auch nicht.
Delphi-Quellcode:
function CopyFileProgress(TotalFileSize, TotalBytesTransferred, StreamSize,
StreamBytesTransferred: LARGE_INTEGER; dwStreamNumber, dwCallbackReason, hSourceFile, hDestinationFile: DWORD; lpData: Pointer): DWORD; stdcall; begin if CancelCopy = True then begin SendMessage(THandle(lpData), CEXM_CANCEL, 0, 0); result:= PROGRESS_CANCEL; exit; end; case dwCallbackReason of CALLBACK_CHUNK_FINISHED: begin SendMessage(THandle(lpData), CEXM_CONTINUE, TotalBytesTransferred.LowPart, TotalBytesTransferred.HighPart); result:= PROGRESS_CONTINUE; end; CALLBACK_STREAM_SWITCH: begin SendMessage(THandle(lpData), CEXM_MAXBYTES, TotalFileSize.LowPart, TotalFileSize.HighPart); result:= PROGRESS_CONTINUE; end; else result:= PROGRESS_CONTINUE; end; end; |
AW: CopyFileEx und Codeoptimierung XE5
Einen Fehle seh ich auf die Schnelle auch noch nicht,
aber im Notfall könntest du ja die Optimierung für die eine einfach Funktion deaktivieren. |
AW: CopyFileEx und Codeoptimierung XE5
Du meinst also, ein reines
Delphi-Quellcode:
fliegt schon raus?
if not CopyFileEx(
'd:\Neues Textdokument.txt', 'd:\Neues Textdokument (Kopie).txt', nil, nil, nil, COPY_FILE_NO_BUFFERING ) then RaiseLastOSError(); |
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:57 Uhr. |
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