Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Form ruft SHBrowseForFolder auf -> Exception (https://www.delphipraxis.net/28814-form-ruft-shbrowseforfolder-auf-exception.html)

sieppl 30. Aug 2004 17:07


Form ruft SHBrowseForFolder auf -> Exception
 
Hallo,

hier wird meine Funktion aufgerufen:
Delphi-Quellcode:
procedure TForm2.Button4Click(Sender: TObject);
var Text: string;
begin
  Text := ShowBrowseForFolder(Form2.Handle);
  if Text <> '' then Edit1.Text := Text;
end;
Die Funktion liegt in einer anderen Unit:
Delphi-Quellcode:
function ShowBrowseForFolder(Handle: HWND): string;
var
  Allocator: IMalloc;
  BrowseInfo: TBrowseInfo;
  Path: PChar;
  PIDL: PItemIDList;

begin
  Result := '';
  if SHGetMalloc(Allocator) = NOERROR then
  begin
    GetMem(Path,MAX_PATH);
    with BrowseInfo do
    begin
        hwndOwner := Handle;
        pidlRoot := nil;
        pszDisplayName := @Path;
        lpszTitle := PChar(Cap_Browse_For_Folder);
        ulFlags := BIF_DONTGOBELOWDOMAIN or BIF_RETURNONLYFSDIRS;
        lParam := 0;
        lpfn := nil;
        iImage := 0;
    end;
    PIDL := SHBrowseForFolder(BrowseInfo);
    if PIDL <> nil then
    begin
      if SHGetPathFromIDList(PIDL, Path) then //HIER EXCEPTION
        Result := string(Path);
    end;
    Allocator.Free(PIDL);
    FreeMem(Path);
  end;
end;
Wenn ich nun in irgendeiner Form auf die zurückgelieferte PIDL zugreife gibt es eine EAccessViolation. (zur Laufzeit natürlich)
Liegt das Problem am Handle? Die PIDL hat natürlich einen Wert. Auch wenn ich sie vorher 'nille'.


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:11 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