Autor Beitrag
Grafix
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Windows 7 Professional
Delphi 2009, PHP, Prolog, Python, Java
BeitragVerfasst: Di 22.03.11 13:17 
Hallo,

ich habe folgende Kopierfunktion im Internet gefunden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
function DoCopy(aOperation: FILEOP_FLAGS; aFrom, aTo: AnsiString;
    Flags: FILEOP_FLAGS): Integer;
var
  FromPath, ToPath: AnsiString;
  SHFileOpStruct: TSHFileOpStruct;
begin
  FromPath := aFrom + #0#0;
  ToPath := aTo + #0#0;
  with SHFileOpStruct do
  begin
    Wnd := 0;
    wFunc := aOperation;
    pFrom := PAnsiChar(FromPath);
    if ToPath <> '' then
    begin
      pTo := PAnsiChar(ToPath)
    end else begin // target available
      pTo := nil;
    end// target not available
    fFlags := Flags;
  end// structure
  Result := SHFileOperationA(SHFileOpStruct);
end;


Hier gibt er mir den Fehler in der Zeile

pFrom := PAnsiChar(FromPath);

Inkompatible Typen: AnsiChar und Char. Ist es weil zu dem AnsiChar der Anhang + #0#0 hinzukam? Wie kann ich das umgehn?
Danke schon mal

Chris
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19339
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 22.03.11 14:46 
Nein, der Fehler liegt hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
function DoCopy(aOperation: FILEOP_FLAGS; aFrom, aTo: AnsiString;
    Flags: FILEOP_FLAGS): Integer;
var
  FromPath, ToPath: AnsiString;
  SHFileOpStruct: TSHFileOpStruct;
Da du die Ansi-Variante statt der Unicodevariante benutzt und Delphi 2009 oder höher nutzt, muss das TSHFileOpStructA heißen.

Nimm besser die Unicodevariante...
Grafix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

Windows 7 Professional
Delphi 2009, PHP, Prolog, Python, Java
BeitragVerfasst: Di 22.03.11 14:54 
Das hat schonmal funktioniert, danke dafür. Worin liegt der Nachteil der Ansi Variante? Die Unicode Variante wäre dass ich alles als Strings usw. deklariere, anstatt PAnsiString oder?

Dazu noch eine weitere Frage, ich möchte, dass der Kopierfortschritt in einer Progressbar auf meinem Form dargestellt wird. Wie kann ich das erreichen?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  if Beide_PC_online = True then begin
    ShowMessage('Beide PCs online, Synchronisierung beginnen');
    for i := 0 to 100 - 1 do begin
      Progressbar.Position := Progressbar.Position +1;
    end;
  end;

  // Kopierfunktion ausführen
  DoCopy(FO_COPY, 'C:\Test\''C:\TestTest\'0);


irgendwie muss ich die Progressbar in die Funktion mit implementieren, ist das ein Lösungsansatz oder wie kann man das realisieren?