IFileDialog.Execute

Syntax

Execute: Boolean;

Description

The Execute method initializes the dialog box and returns the user selection result.

Comments

The method returns True if the Open/Save button was pressed, otherwise, it returns False. If the Open/Save button was pressed, the path and name of the selected file will be available in the FileName property and in the FileNames collection. If for the FileOpenDialog component multiple file selection mode is enabled, the FileNames property contains information about all selected files, and the FileName property contains information only about the first file. Files in the FileNames collection are placed in the same order, which was used to sort them in the dialog box.

Example

Executing the example requires a form with two buttons named B_OPEN and B_SAVE and the FileOpenDialog and FileSaveDialog components named FileOpenDialog1 and FileSaveDialog1 respectively.

Class TESTForm: Form
    Button1: Button;
    Button2: Button;
    FileOpenDialog1: FileOpenDialog;
    FileSaveDialog1: FileSaveDialog;

    Sub B_OPENOnClick(Sender: Object; Args: IMouseEventArgs);
    Var
        FileName: String;
    Begin
        FileOpenDialog1.MultiSelect := True;
        If FileOpenDialog1.Execute Then
            For Each FileName In FileOpenDialog1.FileNames Do
                Debug.WriteLine(FileName);
            End For;
        End If;
    End Sub B_OPENOnClick;

    Sub B_SAVEOnClick(Sender: Object; Args: IMouseEventArgs);
    Begin
        If FileSaveDialog1.Execute Then
            Debug.WriteLine(FileSaveDialog1.FileName);
        End If;
    End Sub B_SAVEOnClick;

End Class TESTForm;

Clicking the B_OPEN button initializes a dialog box of opening files, clicking the B_SAVE button initializes a dialog box of saving to file. On choosing the files and clicking the Save/Open buttons in the dialog boxes information about the files will be displayed in the development environment console.

See also:

IFileDialog