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.

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.

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;

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.

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:

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;

See Also