Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi [TSHFileOpStruct] AV beim löschen eines Ordners (https://www.delphipraxis.net/94356-%5Btshfileopstruct%5D-av-beim-loeschen-eines-ordners.html)

xZise 20. Jun 2007 13:26


[TSHFileOpStruct] AV beim löschen eines Ordners
 
Mit folgenden Code möchte ich einen Ordner + Inhalt löschen:
Delphi-Quellcode:
function DeleteDirectory(const AFile: string): boolean;
var
  Operation: TSHFileOpStruct;
begin
  with Operation do
  begin
    wFunc := FO_DELETE;
    pFrom := PChar(AFile + #0);
    fFlags := FOF_NOCONFIRMATION or FOF_NOERRORUI;
  end;
  Result := SHFileOperation(Operation) = 0;
end;
Aber es gibt in der vorletzten (+end)/ letzten (-end) Zeile eine AV... Nur warum ?

PS: Es ist egal ob AFile ein schließendes "\" hat oder net...

CCRDude 20. Jun 2007 14:11

Re: [TSHFileOpStruct] AV beim löschen eines Ordners
 
Ohne es jetzt ausprobiert zu haben, aber Operation.pTo ist undefiniert, wer weiß was dort gerade drinsteht...?

DeddyH 20. Jun 2007 14:13

Re: [TSHFileOpStruct] AV beim löschen eines Ordners
 
Die AV bekomme ich auch. Wenn ich aber das #0 weglasse, geht es.
Delphi-Quellcode:
pFrom := PChar(AFile);

hoika 20. Jun 2007 14:26

Re: [TSHFileOpStruct] AV beim löschen eines Ordners
 
Hallo,

wie sieht es damit aus ?

Delphi-Quellcode:
function DeleteDirectory(const AFile: string): boolean;
var
  Operation: TSHFileOpStruct;
  szFile: array[0..255] of Char; // jaja MAXPATH oder so
begin
  StrPCopy(szFile, AFile);
  StrCat(szFile, #0);
  with Operation do
  begin
    wFunc := FO_DELETE;
    pFrom := szFile;
    fFlags := FOF_NOCONFIRMATION or FOF_NOERRORUI;
  end;
  Result := SHFileOperation(Operation) = 0;
end;

Heiko

xZise 21. Jun 2007 17:12

Re: [TSHFileOpStruct] AV beim löschen eines Ordners
 
Zitat:

Zitat von CCRDude
Ohne es jetzt ausprobiert zu haben, aber Operation.pTo ist undefiniert, wer weiß was dort gerade drinsteht...?

Also bisher habe ich es nirgends mit pTo gefunden.

Zitat:

Zitat von DeddyH
Die AV bekomme ich auch. Wenn ich aber das #0 weglasse, geht es.
Delphi-Quellcode:
pFrom := PChar(AFile);

Hmm... Jetzt löscht er, wenn er gerade Lust hat einen Ordner :/
Zitat:

Zitat von hoika
Hallo,

wie sieht es damit aus ?

Delphi-Quellcode:
function DeleteDirectory(const AFile: string): boolean;
var
  Operation: TSHFileOpStruct;
  szFile: array[0..255] of Char; // jaja MAXPATH oder so
begin
  StrPCopy(szFile, AFile);
  StrCat(szFile, #0);
  with Operation do
  begin
    wFunc := FO_DELETE;
    pFrom := szFile;
    fFlags := FOF_NOCONFIRMATION or FOF_NOERRORUI;
  end;
  Result := SHFileOperation(Operation) = 0;
end;

Heiko

Ich werds mal probieren.

Hawkeye219 21. Jun 2007 18:00

Re: [TSHFileOpStruct] AV beim löschen eines Ordners
 
Hallo Fabian,

Zitat:

Also bisher habe ich es nirgends mit pTo gefunden.
Die Aussage von Microsoft bezüglich pTo ist eindeutig:

Zitat:

This parameter must be set to NULL if it is not used.
Gruß Hawkeye


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:57 Uhr.

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