Skip to main content
Table of Contents

Directory Selection

TTMSFNCDirectoryEdit combines an edit field with a browse button. The selected path is stored in Text, and IsValidDirectory verifies whether the current value points to an existing directory.

Configure the Editor

Set EmptyText, DialogCaption, and EditorEnabled to control the normal entry flow. Use ButtonSettings and LabelSettings when the editor needs a clear browse command and field label.

Create a Directory EditorPascalC++
TMSFNCDirectoryEdit1.EmptyText := 'Select an output folder';
TMSFNCDirectoryEdit1.DialogCaption := 'Select output folder';
TMSFNCDirectoryEdit1.EditorEnabled := True;
TMSFNCDirectoryEdit1.ButtonSettings.Text := 'Browse';
TMSFNCDirectoryEdit1.ButtonSettings.Align := debaRight;
TMSFNCDirectoryEdit1.LabelSettings.Text := 'Output folder';
TMSFNCDirectoryEdit1.LabelSettings.Position := delpLeftCenter;
TMSFNCDirectoryEdit1.OnDialogClose := TMSFNCDirectoryEdit1DialogClose;
TMSFNCDirectoryEdit1->EmptyText = "Select an output folder";
TMSFNCDirectoryEdit1->DialogCaption = "Select output folder";
TMSFNCDirectoryEdit1->EditorEnabled = true;
TMSFNCDirectoryEdit1->ButtonSettings->Text = "Browse";
TMSFNCDirectoryEdit1->ButtonSettings->Align = debaRight;
TMSFNCDirectoryEdit1->LabelSettings->Text = "Output folder";
TMSFNCDirectoryEdit1->LabelSettings->Position = delpLeftCenter;
TMSFNCDirectoryEdit1->OnDialogClose = TMSFNCDirectoryEdit1DialogClose;

Handle Dialog Results

Handle OnDialogShow to provide an initial path and OnDialogClose to inspect the result. The close event reports whether the user confirmed a directory.

Handle Dialog ResultsPascalC++
procedure TForm1.TMSFNCDirectoryEdit1DialogShow(Sender: TObject; var AInitialPath: string);
begin
  AInitialPath := TMSFNCDirectoryEdit1.Text;
end;

procedure TForm1.TMSFNCDirectoryEdit1DialogClose(Sender: TObject; var AResultPath: string; ASuccess: Boolean);
begin
  if ASuccess and TMSFNCDirectoryEdit1.IsValidDirectory then
    Caption := AResultPath;
end;
void __fastcall TForm1::TMSFNCDirectoryEdit1DialogShow(TObject *Sender, System::UnicodeString &AInitialPath)
{
  AInitialPath = TMSFNCDirectoryEdit1->Text;
}

void __fastcall TForm1::TMSFNCDirectoryEdit1DialogClose(TObject *Sender, System::UnicodeString &AResultPath, bool ASuccess)
{
  if (ASuccess && TMSFNCDirectoryEdit1->IsValidDirectory())
    Caption = AResultPath;
}
Directory edit with an Output folder label and Browse button, showing the confirmed path after the dialog closed and a status line reporting the accepted directory Directory edit with an Output folder label and Browse button, showing the confirmed path after the dialog closed and a status line reporting the accepted directory

Add Directory Lookup

Enable AutoDirectoryLookup when users should receive directory suggestions while typing. The lookup behavior is based on the internal edit control's lookup settings.

Add Directory LookupPascalC++
TMSFNCDirectoryEdit1.AutoDirectoryLookup := True;
TMSFNCDirectoryEdit1.Edit.Lookup.Enabled := True;
TMSFNCDirectoryEdit1.Edit.Lookup.DisplayCount := 6;
TMSFNCDirectoryEdit1.Edit.Lookup.NumChars := 2;
TMSFNCDirectoryEdit1->AutoDirectoryLookup = true;
TMSFNCDirectoryEdit1->Edit->Lookup->Enabled = true;
TMSFNCDirectoryEdit1->Edit->Lookup->DisplayCount = 6;
TMSFNCDirectoryEdit1->Edit->Lookup->NumChars = 2;

Combining editor setup, dialog handling, and autocomplete lookup

The following example configures the editor with a placeholder, opens a pre-seeded dialog, validates the result, and activates directory autocomplete:

Inline example 1PascalC++
procedure TForm1.FormCreate(Sender: TObject);
begin
  TMSFNCDirectoryEdit1.EmptyText       := 'Click browse or type a path…';
  TMSFNCDirectoryEdit1.DialogCaption   := 'Select output folder';
  TMSFNCDirectoryEdit1.AutoDirectoryLookup := True;
end;

procedure TForm1.TMSFNCDirectoryEdit1DialogShow(Sender: TObject;
  var APath: string);
begin
  // Seed dialog with the last confirmed path
  APath := FLastPath;
end;

procedure TForm1.TMSFNCDirectoryEdit1DialogClose(Sender: TObject;
  APath: string; AAccepted: Boolean);
begin
  if AAccepted and DirectoryExists(APath) then
  begin
    FLastPath := APath;
    btnExport.Enabled := True;
  end;
end;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  TMSFNCDirectoryEdit1->EmptyText = L"Click browse or type a path…";
  TMSFNCDirectoryEdit1->DialogCaption = L"Select output folder";
  TMSFNCDirectoryEdit1->AutoDirectoryLookup = true;
}

void __fastcall TForm1::TMSFNCDirectoryEdit1DialogShow(TObject *Sender,
  System::UnicodeString &APath)
{
  APath = FLastPath;
}

void __fastcall TForm1::TMSFNCDirectoryEdit1DialogClose(TObject *Sender,
  System::UnicodeString &APath, bool AAccepted)
{
  if (AAccepted && DirectoryExists(APath)) {
    FLastPath = APath;
    btnExport->Enabled = true;
  }
}
Directory edit with automatic directory lookup: a typed C:\Windows\Sys prefix lists the six matching folders, and the Export button stays disabled until a directory is confirmed Directory edit with automatic directory lookup: a typed C:\Windows\Sys prefix lists the six matching folders, and the Export button stays disabled until a directory is confirmed

See Also