0

I've seen this question: Selecting a directory with TOpenDialog

Which technically is NOT answered (OP asked SPECIFICALLY about TOpenDialog - not TFileOpenDialog) but is applicable to later versions of Delphi.

I'm using Delphi 7 so TFileOpenDialog is not available.

So is it possible to use TOpenDialog to select a folder?

I know about SelectDirectory and have seen the other postings on that and I also know about BrowseFolder.

I am ONLY interested in answers that pertain to TOpenDialog.

I tried setting the Filename property to '*.' as someone suggested somewhere but that doesn't work.

Community
  • 1
  • 1
Toby
  • 355
  • 6
  • 14

1 Answers1

3

I've seen this question: Selecting a directory with TOpenDialog

Which technically is NOT answered

It is, well in one of the comments anyway:

"TFileOpenDialog != TOpenDialog ... TOpenDialog doesn't have such an option"

That is the answer.

I'm using Delphi 7 so TFileOpenDialog is not available.

No, it is not. However, the underlying IFileDialog and IFileOpenDialog interfaces that it uses internally are standard Win32 COM interfaces (on Vista+ only), and as such they can be used in Delphi 7 just fine, as long as you have their declarations in your code.

So is it possible to use TOpenDialog to select a folder?

The short answer is NO.

In Delphi 7, TOpenDialog is just a wrapper for the Win32 API GetOpenFileName() function, which can only select and return files, not folders. You must use SelectDirectory() (which is just a wrapper for the Win32 API SHBrowseForFolder() function if you use the newer overload), or IFileDialog/IFileOpenDialog with the FOS_PICKFOLDERS option enabled.

In modern versions of Delphi, TOpenDialog does delegate to IFileDialog/IFileOpenDialog on Vista+ whenever possible (theming enabled, not using old VCL features that not expose by the newer dialog, etc), but it does not enable the FOS_PICKFOLDERS option.

Community
  • 1
  • 1
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I saw that comment but thought it was related to the specific TFileOpenDialog option mentioned (fdoPickFolders). That's pretty much the answer I expected but wanted to be sure. Thx for the additional info - I'll take a look at the interfaces. – Toby Mar 23 '17 at 22:11