TSelectDirectory Object

Applies to TestComplete 15.68, last modified on October 16, 2024

The TSelectDirectory component represents a modal dialog where a user can select a folder. If needed, the user can create a new folder by clicking the dialog’s Make New Folder button.

The starting location of the shell tree displayed in the dialog is specified by the RootFolderType or CustomRootFolder property. To display the dialog, call the Execute method. You can use the return value of this method to obtain the dialog's result. To get or set the path to the selected folder, use the Directory property.

The following example demonstrates the use of the TSelectDirectory component in scripts. It requires a form named Form1 with the TcxMRUEdit component named cxMRUEdit1 and the TSelectDirectory component named TSelectDirectory1. The edit box should be used to specify the folder path. The Form1_cxMRUEdit1_OnButtonClick routine should be assigned as an event handler for the OnButtonClick event. It displays the dialog and initially selects the folder specified in the edit box. If the user chose another folder in the dialog and pressed the OK button, the edit box text is replaced with the path to the selected folder.

JavaScript, JScript

function Form1_cxMRUEdit1_OnButtonClick(Sender)
{
  var dialog = UserForms.Form1.SelectDirectory1;
  dialog.Directory = Sender.Text;
  if (dialog.Execute())
  {
    Sender.Text = dialog.Directory;
    Sender.Properties.LookupItems.Add(dialog.Directory);
  }
}

Python

def Form1_cxMRUEdit1_OnButtonClick(Sender):
  dialog = UserForms.Form1.SelectDirectory1
  dialog.Directory = Sender.Text
  if (dialog.Execute()):
    Sender.Text = dialog.Directory
    Sender.Properties.LookupItems.Add(dialog.Directory)

VBScript

Sub Form1_cxMRUEdit1_OnButtonClick (Sender)
  Set dialog = UserForms.Form1.SelectDirectory1
  dialog.Directory = Sender.Text
  If dialog.Execute Then
    Sender.Text = dialog.Directory
    Sender.Properties.LookupItems.Add dialog.Directory
  End If
End Sub

DelphiScript

procedure Form1_cxMRUEdit1_OnButtonClick(Sender: OleVariant);
var
  dialog: OleVariant;
begin
  dialog := UserForms.Form1.SelectDirectory1;
  dialog.Directory := Sender.Text;
  if dialog.Execute then
  begin
    Sender.Text := dialog.Directory;
    Sender.Properties.LookupItems.Add(dialog.Directory);
  end;
end;

C++Script, C#Script

function Form1_cxMRUEdit1_OnButtonClick(Sender)
{
  var dialog = UserForms["Form1"]["SelectDirectory1"];
  dialog["Directory"] = Sender["Text"];
  if (dialog["Execute"]())
  {
    Sender["Text"] = dialog["Directory"];
    Sender["Properties"]["LookupItems"]["Add"](dialog["Directory"]);
  }
}

The TSelectDirectory component raises a number of events that you can process in your scripts. For example, you can create an event handler for the OnShow event to perform desired actions when the dialog is displayed.

TSelectDirectory Properties

TSelectDirectory Methods

TSelectDirectory Events

See Also

User Forms
TOpenDialog Object
TSaveDialog Object

Highlight search results