Howto Use TOpenDialog: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | Simple and short guidelines: | |
| 2 | 2 | ||
| 3 | 3 | 1\. Place a [[TOpenDialog]] widget  on your [[TForm|form]]. It can be placed anywhere on your form as it is not visible during program [[runtime|run time]] but only during design time. | |
| 4 | 4 | ||
| 5 | - | ||
| 5 | + | ```text | |
| 6 | + | Image:Component_Palette_Dialogs.png | |
| 7 | + | ``` | |
| 6 | 8 | ||
| 7 | 9 | It is located in the [[Dialogs tab]] of the [[Component Palette|component palette]] and is the leftmost component. | |
| 8 | 10 | ||
| 9 | 11 | 2\. In your code write something similar to: | |
| 10 | 12 | ||
| 11 | 13 | ``` pascal | |
| 12 | 14 | if OpenDialog1.Execute then | |
| 13 | 15 | begin | |
| 14 | 16 | if fileExists(OpenDialog1.Filename) then | |
| 15 | 17 | ShowMessage(OpenDialog1.Filename); | |
| 16 | 18 | end | |
| 17 | 19 | else | |
| 18 | 20 | ShowMessage('No file selected'); | |
| 19 | 21 | ``` | |
| 20 | 22 | ||
| 21 | 23 | The dialog [[doc:lcl/dialogs/tcommondialog.execute.html|Execute]] [[Method|method]] displays the file open dialog. It returns [[True|true]] when user has selected a file, [[False|false]] when user has aborted. | |
| 22 | 24 | ||
| 23 | 25 | The dialog [[doc:lcl/dialogs/tfiledialog.filename.html|Filename]] [[Property|property]] returns the full filename including drive and path. | |
| 24 | 26 | ||
| 25 | 27 | > **Note:** This control only collects the filename. It does not actually open the file. Your code must do that. | |
| 26 | 28 | ||
| 27 | 29 | ## See also | |
| 28 | 30 | ||
| 29 | 31 | - [[Howto Use TSaveDialog]] | |
| 30 | 32 | - [[CopyFile]] | |
| 31 | 33 | ||
| 32 | 34 | --- | |
| 33 | 35 | *From the Free Pascal wiki, page "Howto Use TOpenDialog", as it stood on 2021-03-27 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
