TOpenDialog Object

Applies to TestComplete 15.63, last modified on April 10, 2024

The TOpenDialog component is a file-selection modal dialog where a user can select and open one or several files. TOpenDialog contains a number of specific properties, methods and events that let you control various aspects of the dialog’s appearance and behavior.

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 the path to the selected file, use the FileName property. The Files property lets you get a list of files selected in the dialog.

The following example demonstrates the use of the TOpenDialog component in scripts. It requires a form named Form1 with the TcxLabel component named cxLabel1, the TcxMemo component named cxMemo1 and the TOpenDialog component named OpenDialog1. The code displays the dialog, and if the user chose the file and pressed the Open button, the name of the selected file is stored to the label text and the file's contents are loaded to the memo.

JavaScript, JScript

var form = UserForms.Form1;
var oDialog = form.OpenDialog1;
if (oDialog.Execute())
{
  form.cxLabel1.Caption = oDialog.FileName;
  form.cxMemo1.Lines.LoadFromFile(oDialog.FileName);
}

Python

form = UserForms.Form1
oDialog = form.OpenDialog1
if (oDialog.Execute()):
  form.cxLabel1.Caption = oDialog.FileName
  form.cxMemo1.Lines.LoadFromFile(oDialog.FileName)

VBScript

Set form = UserForms.Form1
Set oDialog = form.OpenDialog1
If oDialog.Execute Then
  form.cxLabel1.Caption = oDialog.FileName
  form.cxMemo1.Lines.LoadFromFile(oDialog.FileName)
End If

DelphiScript

var
  form, oDialog : OleVariant;
...
form := UserForms.Form1;
oDialog := form.OpenDialog1;
if oDialog.Execute then
begin
  form.cxLabel1.Caption := oDialog.FileName;
  form.cxMemo1.Lines.LoadFromFile(oDialog.FileName);
end;

C++Script, C#Script

var form = UserForms["Form1"];
var oDialog = form.OpenDialog1;
if (oDialog["Execute"]())
{
  form["cxLabel1"]["Caption"] = oDialog["FileName"];;
  form["cxMemo1"]["Lines"]["LoadFromFile"](oDialog["FileName"]);
}

The TOpenDialog component raises a number of events that you can process in your scripts. For example, you can create an event handler for the OnSelectionChange event to perform desired actions when the selected files or the list of selected files are changed.

TOpenDialog Properties

TOpenDialog Methods

TOpenDialog Events

See Also

User Forms
TSaveDialog Object
TSelectDirectory Object

Highlight search results