Recent

Author Topic: TSelectDirectoryDialog will not let me create a folder ?  (Read 1562 times)

jamie

  • Hero Member
  • *****
  • Posts: 6090
TSelectDirectoryDialog will not let me create a folder ?
« on: April 11, 2020, 09:39:41 pm »
 I can't say what the issue is but when I use this to select a folder and then I want an inner tree to the folder I have selected I type it in at the bottom it tells me it does not exist and ask me if I want to create it, I say Yes of course and it always comes back with a failure. Sometimes it gives me a network path check etc...

  I am pretty sure I've used this before for doing this...

 I checked marked the option to create a prompt on creation and that works but it still fails to create it.

 This is Win10, this is getting frustrating.

 P.S.
   I just tried with the OldStlyle Dialog and it works there...
guess I'll have to live with that, there is something wrong with the current style it does not work!

« Last Edit: April 11, 2020, 09:44:10 pm by jamie »
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TSelectDirectoryDialog will not let me create a folder ?
« Reply #1 on: April 11, 2020, 11:36:36 pm »
Yep, same thing here.
Did that ever work?

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TSelectDirectoryDialog will not let me create a folder ?
« Reply #2 on: April 11, 2020, 11:52:48 pm »
From: https://docs.microsoft.com/nl-nl/windows/win32/api/shobjidl_core/ne-shobjidl_core-_fileopendialogoptions

Quote
FOS_CREATEPROMPT    Prompt for creation if the item returned in the save dialog does not exist. Note that this does not actually create the item.

Bart

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TSelectDirectoryDialog will not let me create a folder ?
« Reply #3 on: April 12, 2020, 12:20:12 am »
Well it does not work ether way, I get the failed attempt prompt or no prompt.
 
I think there is suppose to be a handler notify so your code can actually create it and thus what is happening it test for the actual file afterwards ..

  Basically I believe there  is a missing event in the LCL part of it so user can make the creation.
« Last Edit: April 12, 2020, 12:23:56 am by jamie »
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: TSelectDirectoryDialog will not let me create a folder ?
« Reply #4 on: April 12, 2020, 10:25:30 pm »
Well, the IFileDialogEvents are listed here: https://docs.microsoft.com/nl-nl/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifiledialogevents.

I can't see an appropriate event there.

Bart
« Last Edit: April 12, 2020, 11:32:26 pm by Bart »

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: TSelectDirectoryDialog will not let me create a folder ?
« Reply #5 on: April 12, 2020, 10:56:12 pm »
I will need to check this again, it could be possible it is looking for a shell extension at the start or shell name space.
 For example the C:\ etc...

 If I can figure this out I may be able to document it but if this is the case then maybe the code could be enhanced to auto adjust it..
The only true wisdom is knowing you know nothing

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: TSelectDirectoryDialog will not let me create a folder ?
« Reply #6 on: April 13, 2020, 01:31:02 am »
I can't say what the issue is but when I use this to select a folder and then I want an inner tree to the folder I have selected I type it in at the bottom it tells me it does not exist and ask me if I want to create it, I say Yes of course and it always comes back with a failure.
It looks like an OS limitation. I create a simple test:
Code: Pascal  [Select][+][-]
  1. uses ActiveX, ShlObj, Win32Extra;
  2.  
  3. function SelectDirectory(const Caption: string; var Dir: string): Boolean;
  4. const
  5.   COptions = FOS_CREATEPROMPT or
  6.     //FOS_PICKFOLDERS or
  7.     FOS_FORCEFILESYSTEM;
  8. var
  9.   Dialog: IFileOpenDialog;
  10.   Folder: UnicodeString;
  11.   FolderItem: IShellItem;
  12.   Buf: PWideChar = nil;
  13.   Wnd: THandle = 0;
  14. begin
  15.   Result := CoCreateInstance(CLSID_FileOpenDialog, nil, CLSCTX_INPROC_SERVER, IFileOpenDialog, Dialog) = S_OK;
  16.   if not Result then
  17.     Exit;
  18.   Folder := UTF8Decode(Dir);
  19.   if SHCreateItemFromParsingName(PWideChar(Folder), nil, IShellItem, FolderItem) = S_OK then
  20.     Dialog.SetFolder(FolderItem);
  21.   Dialog.SetTitle(PWideChar(UTF8Decode(Caption)));
  22.   Dialog.SetOptions(COptions);
  23.   if Assigned(Application) and Assigned(Application.MainForm) then
  24.     Wnd := Application.MainForm.Handle;
  25.   Result := Dialog.Show(Wnd) = S_OK;
  26.   if Result then
  27.   begin
  28.     if (Dialog.GetResult(@FolderItem) <> S_OK) or (FolderItem.GetDisplayName(SIGDN(SIGDN_FILESYSPATH), @Buf) <> S_OK) then
  29.       RaiseLastOSError;
  30.     Folder := Buf;
  31.     CoTaskMemFree(Buf);
  32.     Dir := UTF8Encode(Folder);
  33.   end;
  34. end;
  35.  
  36. procedure TForm1.Button1Click(Sender: TObject);
  37. var
  38.   S: string = 'c:\temp\6';
  39. begin
  40.   if SelectDirectory('Test', S) then
  41.     Caption := S
  42.   else
  43.     Caption := '{cancel}';
  44. end;
When the FOS_PICKFOLDERS option is enabled, elements are always checked.

 

TinyPortal © 2005-2018