OpenDialog#
Qualified name: delphivcl.OpenDialog
- class OpenDialog#
Bases:
Component
TOpenDialog displays a file-selection dialog. TOpenDialog displays a modal Windows dialog box for selecting and opening files. The dialog does not appear at runtime until it is activated by a call to the Execute method. When the user clicks Open, the dialog closes and the selected file or files are stored in the Files property.
Methods
Creates and initializes a TOpenDialog instance.
Destroys the TOpenDialog and frees its memory.
Displays the file-selection dialog.
Attributes
ClassName
Returns the TObject.ClassName
ComObject
Specifies the interface reference implemented by the component.
ComponentCount
Indicates the number of components owned by the component.
ComponentIndex
Indicates the position of the component in its owner's Components property array.
ComponentState
Describes the current state of the component, indicating when a component needs to avoid certain actions.
ComponentStyle
Governs the behavior of the component.
Components
<Delphi indexed property Components of type TComponent at 21141642500>
Specifies a default file extension.
DesignInfo
Contains information used by the Form designer.
Determines the style of the file-selection dialog.
Indicates the name and directory path of the last file selected.
List of selected file names.
Determines the file masks (filters) available in the dialog. The file-selection dialog includes a drop-down list of file types under the edit box. When the user picks a file type from the list, only files of the selected type are displayed in the dialog. To configure file masks at design time, click on the ellipsis marks (...) to the right of the Filter property in the Object Inspector. This opens the Filter editor. In the left column of the Filter editor, under Filter Name, type a brief description of each file type that will be available at runtime. In the right column, under Filter, type the file mask corresponding to each description. For example, the description "Text files" might appear to the left of the mask ".txt", and the description "Pascal source files" might appear to the left of the mask ".pas". Since the description appears in the drop-down list at runtime, it is often helpful to show the mask explicitly in the description (for example, "Text files (*.txt)"). To create file masks in program code, assign a value to the Filter property that consists of a description and a mask separated by a vertical bar (pipe) character. Do not include spaces around the vertical bar. For example,.
Determines which filter is selected by default when the dialog opens.
Maintains a list of previously selected files.
Determines the current directory when the dialog opens.
Name
Specifies the name of the component as referenced in code.
Observers
Indicates the TObservers object added to the TComponent.
<Delphi property OnCanClose of type TOpenDialog at 21141BF27D0>
<Delphi property OnFolderChange of type TOpenDialog at 21141BF28A0>
<Delphi property OnIncludeItem of type TOpenDialog at 21141BF2B10>
<Delphi property OnSelectionChange of type TOpenDialog at 21141BF2970>
<Delphi property OnTypeChange of type TOpenDialog at 21141BF2A40>
Determines the appearance and behavior of the file-selection dialog.
Augments the Options property with additional flags that determine the appearance and behavior of the file-selection dialog.
Owner
Indicates the component that is responsible for streaming and freeing this component.
Tag
Stores a NativeInt integral value as a part of a component.
Specifies the text in the dialog's title bar.
VCLComObject
Represents information used internally by components that support COM.
- Create(AOwner: Component)#
Creates and initializes a TOpenDialog instance. Create generates a TOpenDialog instance, but the new dialog does not appear on the form at runtime until the Execute method is called. AOwner is the component that is responsible for freeing the TOpenDialog instance. It becomes the value of the Owner property.
- DefaultExt#
Specifies a default file extension. DefaultExt specifies a file extension that is appended automatically to the selected file name, unless the selected file name already includes a registered extension. If the user selects a file name with an extension that is unregistered, DefaultExt is appended to the unregistered extension. Extensions longer than three characters are not supported. Do not include the period (.) that divides the file name and its extension.
Code Examples SavePictureDialog (Delphi) TApplicationIcon (Delphi) SavePictureDialog (C++) TApplicationIcon (C++)
- Destroy()#
Destroys the TOpenDialog and frees its memory. Do not call Destroy directly in an application. Call Free instead. Free verifies that the TOpenDialog reference is not nil before calling Destroy.
- Execute(ParentWnd: HWND) Boolean #
Displays the file-selection dialog. Execute opens the file-selection dialog, returning true when the user selects a file and clicks Open. If the user clicks Cancel, Execute returns false. The code signatures of Execute that appear above are actually overrides of the Execute overloads in the base class Vcl.Dialogs.TCommonDialog.Execute. There is one more overload of Execute for Delphi that appears in the inherited members from TCommonDialog, and this overload takes no input parameters. The ParentWnd parameter is a window handle of type HWND MSDN. If none is provided, the current form handle is used, accessed from Vcl.Forms.TApplication.ActiveFormHandle in the global variable Vcl.Forms.Application.
// Delphi: if OpenDialog1.Execute then
Memo1.Lines.LoadFromFile(OpenDialog1.FileName)
- else
Memo1.Lines.Clear;
// C++: if (OpenDialog1->Execute())
Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
- else
Memo1->Lines->Clear();
- FileEditStyle#
Determines the style of the file-selection dialog. (Obsolete.) FileEditStyle is maintained for compatibility with older versions of the VCL. It has no effect.
- FileName#
Indicates the name and directory path of the last file selected. The FileName property returns the name and complete directory path of the most recently selected file. The value of FileName is the same as the first item in the Files property. To make a file name appear by default in the dialog’s edit box, assign a value to FileName in the Object Inspector or in program code. Programmatic changes to FileName have no effect while the dialog is active.
- if OpenDialog1.Execute then
Memo1.Lines.LoadFromFile(OpenDialog1.FileName)
- else
Memo1.Lines.Clear;
- if (OpenDialog1->Execute())
Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
- else
Memo1->Clear();
- Files#
List of selected file names. Files is a string list that contains each selected file name with its full directory path. (To let users select multiple file names, set the ofAllowMultiSelect flag in Options.) Use properties and methods for string lists to traverse this list of files and read individual items. The example below assigns the list of files in Files to the Items property of a TListBox component.
ListBox1.Items.Assign(OpenDialog1.Files);
ListBox1->Items->Assign(OpenDialog1->Files);
- Filter#
Determines the file masks (filters) available in the dialog. The file-selection dialog includes a drop-down list of file types under the edit box. When the user picks a file type from the list, only files of the selected type are displayed in the dialog. To configure file masks at design time, click on the ellipsis marks (…) to the right of the Filter property in the Object Inspector. This opens the Filter editor. In the left column of the Filter editor, under Filter Name, type a brief description of each file type that will be available at runtime. In the right column, under Filter, type the file mask corresponding to each description. For example, the description “Text files” might appear to the left of the mask “.txt”, and the description “Pascal source files” might appear to the left of the mask “.pas”. Since the description appears in the drop-down list at runtime, it is often helpful to show the mask explicitly in the description (for example, “Text files (*.txt)”). To create file masks in program code, assign a value to the Filter property that consists of a description and a mask separated by a vertical bar (pipe) character. Do not include spaces around the vertical bar. For example,
OpenDialog1.Filter := ‘Text files (.txt)|.TXT’;
OpenDialog1->Filter = “Text files (.txt)|.TXT”;
Multiple filters should be separated by vertical bars. For example,
OpenDialog1.Filter := ‘Text files (.txt)|.TXT|Pascal files (.pas)|.PAS’;
OpenDialog1->Filter = “Text files (.txt)|.TXT|Pascal files (.pas)|.PAS”;
To include multiple masks in a single filter, separate the masks with semicolons. This works both in the Object Inspector and in program code. For example,
OpenDialog1.Filter := ‘Pascal files|*.PAS;*.DPK;*.DPR’;
OpenDialog1->Filter = “Pascal files|*.PAS;*.DPK;*.DPR”;
If no value is assigned to Filter, the dialog displays all file types.
- FilterIndex#
Determines which filter is selected by default when the dialog opens. FilterIndex determines which of the file types in Filter is selected by default when the dialog opens. Set FilterIndex to 1 to choose the first file type in the list as the default, or set FilterIndex to 2 to choose the second file type as the default, and so forth. If the value of FilterIndex is out or range, the first file type listed in Filter is the default.
- HistoryList#
Maintains a list of previously selected files. (Obsolete.) HistoryList is maintained for compatibility with older versions of TOpenDialog. It is not used.
- InitialDir#
Determines the current directory when the dialog opens. InitialDir determines the default directory displayed in the file-selection dialog when it opens. For example, to point the dialog at the WINDOWSSYSTEM directory, set the value of InitialDir to C:WINDOWSSYSTEM. If no value is assigned to InitialDir, or if the specified directory does not exist, the initial directory is controlled by the global ForceCurrentDirectory variable. If ForceCurrentDirectory is true, the dialog opens with the current working directory displayed. Otherwise, the dialog opens with either the current working directory or the My Documents directory, depending on the version of Windows.
- OnCanClose#
<Delphi property OnCanClose of type TOpenDialog at 21141BF27D0>
- OnFolderChange#
<Delphi property OnFolderChange of type TOpenDialog at 21141BF28A0>
- OnIncludeItem#
<Delphi property OnIncludeItem of type TOpenDialog at 21141BF2B10>
- OnSelectionChange#
<Delphi property OnSelectionChange of type TOpenDialog at 21141BF2970>
- OnTypeChange#
<Delphi property OnTypeChange of type TOpenDialog at 21141BF2A40>
- Options#
Determines the appearance and behavior of the file-selection dialog. Use the Options property to customize the appearance and functionality of the dialog.
- OptionsEx#
Augments the Options property with additional flags that determine the appearance and behavior of the file-selection dialog. Use the OptionsEx property to further customize the file open dialog beyond the options covered by the Options property.
- Title#
Specifies the text in the dialog’s title bar. Use Title to specify the text that appears in the file-selection dialog’s title bar. If no value is assigned to Title, the dialog has the title “Open”.
Code Examples TOpenDialogTitle (Delphi) TOpenDialogTitle (C++)