DELPHI - How to use opendialog1 for choosing a folder?

Galvion picture Galvion · Mar 2, 2012 · Viewed 34.2k times · Source

Possible Duplicate:
Delphi: Selecting a directory with TOpenDialog

I need to open a specific folder on my project. When I use opendialog1, I can only open a file. How about opening a folder ?

wanted - open folder dialog in Delphi

PS : I use Delphi 2010

Answer

David Heffernan picture David Heffernan · Mar 2, 2012

On Vista and up you can show a more modern looking dialog using TFileOpenDialog.

var
  OpenDialog: TFileOpenDialog;
  SelectedFolder: string;
.....
OpenDialog := TFileOpenDialog.Create(MainForm);
try
  OpenDialog.Options := OpenDialog.Options + [fdoPickFolders];
  if not OpenDialog.Execute then
    Abort;
  SelectedFolder := OpenDialog.FileName;
finally
  OpenDialog.Free;
end;

which looks like this:

enter image description here