TOpenOption and TOpenOptions determine the behavior of a file selection dialog.
TOpenOptions = set of TOpenOption;
TOpenOption TOpenOptions;
TOpenOption values determine the appearance and behavior of a file selection dialog. TOpenOptions is a set of TOpenOption values.
The following table lists the possible values:
Value |
Meaning |
ofReadOnly |
Selects the Open As Read Only check box by default when the dialog opens. |
ofOverwritePrompt |
Generates a warning message if the user tries to select a file name that is already in use, asking whether to overwrite the existing file. (Use with save dialogs.) |
ofHideReadOnly |
Removes the Open As Read Only check box from the dialog. |
ofNoChangeDir |
After the user clicks OK, resets the current directory to whatever it was before the file-selection dialog opened. |
ofShowHelp |
Displays a Help button in the dialog. |
ofNoValidate |
Disables checking for invalid characters in file names. Allows selection of file names with invalid characters. |
ofAllowMultiSelect |
Allows users to select more than one file in the dialog. |
ofExtensionDifferent |
This flag is turned on at runtime whenever the selected filename has an extension that differs from DefaultExt. If you use this flag in an application, remember to reset it. |
ofPathMustExist |
Generates an error message if the user tries to select a file name with a nonexistent directory path. |
ofFileMustExist |
Generates an error message if the user tries to select a nonexistent file. (only applies to Open dialogs). |
ofCreatePrompt |
Generates a warning message if the user tries to select a nonexistent file, asking whether to create a new file with the specified name. |
ofShareAware |
Ignores sharing errors and allows files to be selected even when sharing violations occur. |
ofNoReadOnlyReturn |
Generates an error message if the user tries to select a read-only file. |
ofNoTestFileCreate |
Disables checking for network file protection and inaccessibility of disk drives. Applies only when the user tries to save a file in a create-no-modify shared network directory. |
ofNoNetworkButton |
Removes the Network button (which opens a Map Network Drive dialog) from the file-selection dialog. Applies only if the ofOldStyleDialog flag is on. |
ofNoLongNames |
Displays 8.3-character file names only. This option is only valid if Options also includes ofOldStyleDialog. |
ofOldStyleDialog |
Creates the older style of file-selection dialog. |
ofNoDereferenceLinks |
Disables dereferencing of Windows shortcuts. If the user selects a shortcut, assigns to FileName the path and file name of the shortcut itself (the .LNK file), rather than the file linked to the shortcut. |
ofEnableIncludeNotify |
(Windows 2000 and later.) Sends CDN_INCLUDEITEM notification messages to the dialog when the user opens a folder. A notification is sent for each item in the newly opened folder. You can use these messages to control which items appear in the folder's item list. |
ofEnableSizing |
(Windows 98 and later) Lets the Explorer-style dialog be resized with the mouse or keyboard. By default, the dialog allows this resizing regardless of the value of this option. It is only required if you provide a hook procedure or custom template. (Old style dialogs never permit resizing.) |
ofDontAddToRecent |
Prevents the file from being added to the list of recently opened files. |
ofForceShowHidden |
Ensures that hidden files are visible in the dialog. |
C++ Examples:
/* The following code allows the user to use a dialog box to redefine the icon for the application at run time. When the user clicks Button1, OpenDialog1 executes and the user specifies an icon filename. The Icon is then assigned to the application. At runtime, click Button1 to select the icon, then minimize the application to see the icon. */ void __fastcall TForm1::Button1Click(TObject *Sender) { OpenPictureDialog1->DefaultExt = GraphicExtension(__classid(TIcon)); OpenPictureDialog1->FileName = GraphicFileMask(__classid(TIcon)); OpenPictureDialog1->Filter = GraphicFilter(__classid(TIcon)); OpenPictureDialog1->Options.Clear(); OpenPictureDialog1->Options << ofFileMustExist << ofHideReadOnly << ofNoChangeDir; while (true) { if (OpenPictureDialog1->Execute()) { if (!OpenPictureDialog1->Options.Contains(ofExtensionDifferent)) { Application->Icon->LoadFromFile(OpenPictureDialog1->FileName); break; } else // reset Options to remove ofExtensionDifferent { OpenPictureDialog1->Options.Clear(); OpenPictureDialog1->Options << ofFileMustExist << ofHideReadOnly << ofNoChangeDir; } } else // user cancelled break; } }
Delphi Examples:
{ The following code allows the user to use a dialog box to redefine the icon for the application at run time. When the user clicks Button1, OpenDialog1 executes and the user specifies an icon filename. The Icon is then assigned to the application. At runtime, click Button1 to select the icon, then minimize the application to see the icon. } procedure TForm1.Button1Click(Sender: TObject); var Done: Boolean; filenamestring : String; begin OpenPictureDialog1.DefaultExt := GraphicExtension(TIcon); filenamestring := GraphicFileMask(TIcon); OpenPictureDialog1.FileName := filenamestring; OpenPictureDialog1.Filter := GraphicFilter(TIcon); OpenPictureDialog1.Options := [ ofFileMustExist, ofHideReadOnly, ofNoChangeDir ]; Done := False; while not Done do begin if OpenPictureDialog1.Execute then begin if not (ofExtensionDifferent in OpenPictureDialog1.Options) then begin Application.Icon.LoadFromFile(OpenPictureDialog1.FileName); Done := True; end else // OpenPictureDialog1.Options := OpenPictureDialog1.Options - ofExtensionDifferent; end else { User cancelled } Done := True; end; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|