2009/09/09 08:03

Is there directory selection VCL component in Delphi ?


There are FileOpenDialog and FileSaveDialog components on Delphi VCL.
Sometimes you may need Directory Selection dialog, but no components are found on VCL.
Do you know Delphi provides the solution as SelectDirectory().

Here are two examples for Directory Selection.

Following shows directory structure under d:\delphi
procedure TForm1.Button1Click(Sender: TObject);
var
  DirSelected: string;
begin
  if SelectDirectory('Select a folder:', 'D:\Delphi', DirSelected) then
    ShowMessage('You selected ' + DirSelected)
  else
    ShowMessage('You did not select a folder');
end;


Following shows driver names and files as well as directory structure.
procedure TForm1.Button2Click(Sender: TObject);
var
  Dir: string;
begin
  Dir := 'D:\Delphi';
  if SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
    ShowMessage('You selected ' + Dir)
  else
    ShowMessage('You did not select a folder');
end;

Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.