SelectDirectory (Delphi)
Contents
Description
This example requires a button and a label on a form. When you click the button, a Select Directory dialog box appears. The current directory displayed in the dialog box is C:\WINDOWS for VCL, and in the user's documents folder (C:\Users\<username>\Documents in Windows) for FMX. You can select a directory from the directory list, or enter a new directory in the edit box. If you enter a new directory, a message box asks you if the directory should be created. If you choose Yes, the directory is created. If you choose No, the message box goes away without creating the directory. The name of the directory selected by you appears as the caption of the label.
Code
VCL
uses FileCtrl;
const
SELDIRHELP = 1000;
procedure TForm1.Button1Click(Sender: TObject);
var
Dir: string;
begin
Dir := 'C:\Windows';
if FileCtrl.SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP) then
Label1.Caption := Dir;
end;
FMX
uses
System.IOUtils;
procedure TForm1.Button1Click(Sender: TObject);
var
Dir: string;
begin
if SelectDirectory('Select document folder', System.IOUtils.TPath.GetDocumentsPath, Dir) then
Label1.Text := Dir;
end;
Uses
- Vcl.FileCtrl.SelectDirectory ( fr | de | ja )
- Vcl.FileCtrl.TSelectDirOpt ( fr | de | ja )
- FMX.Dialogs.SelectDirectory ( fr | de | ja )