Advertisement
Gov_777

Выбор папки диалог

Jun 16th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.92 KB | None | 0 0
  1. function SelectDirectory(const Title: string; var Path: string): Boolean;
  2. var
  3.   lpItemID: PItemIDList;
  4.   BrowseInfo: TBrowseInfo;
  5.   DisplayName: array[0..MAX_PATH] of char;
  6.   TempPath: array[0..MAX_PATH] of char;
  7. begin
  8.   FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
  9.   BrowseInfo.hwndOwner := 0;
  10.   BrowseInfo.pszDisplayName := @DisplayName;
  11.   BrowseInfo.lpszTitle := PChar(Title);
  12.   BrowseInfo.ulFlags := BIF_RETURNONLYFSDIRS;
  13.   lpItemID := SHBrowseForFolder(BrowseInfo);
  14.   Result := lpItemID <> nil;
  15.   if Result then
  16.   begin
  17.     SHGetPathFromIDList(lpItemID, TempPath);
  18.     Path := TempPath;
  19.     GlobalFreePtr(lpItemID);
  20.   end;
  21. end;
  22.  
  23. procedure Tmain.SpeedButton1Click(Sender: TObject);
  24. var
  25.   chosenDirectory: string;
  26. begin
  27.   if SelectDirectory('Выберите каталог', chosenDirectory) then
  28.     Edit1.Text := chosenDirectory
  29.   else
  30.     ShowMessage('Выбор каталога прервался');
  31. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement