Sign in Join
Wiki copytemporary

Howto Use TOpenDialog: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Howto Use TOpenDialog

OldNewLine
1+Simple and short guidelines:
2+
3+1\. Place a [[TOpenDialog]] widget ![](/wiki-images/9/90/Topendialog.png) 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+
5+![`Component_Palette_Dialogs.png`](/wiki-images/7/72/Component_Palette_Dialogs.png)` `
6+
7+It is located in the [[Dialogs tab]] of the [[Component Palette|component palette]] and is the leftmost component.
8+
9+2\. In your code write something similar to:
10+
11+``` pascal
12+if OpenDialog1.Execute then
13+ begin
14+ if fileExists(OpenDialog1.Filename) then
15+ ShowMessage(OpenDialog1.Filename);
16+ end
17+else
18+ ShowMessage('No file selected');
19+```
20+
21+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+
23+The dialog [[doc:lcl/dialogs/tfiledialog.filename.html|Filename]] [[Property|property]] returns the full filename including drive and path.
24+
25+> **Note:** This control only collects the filename. It does not actually open the file. Your code must do that.
26+
27+## See also
28+
29+- [[Howto Use TSaveDialog]]
30+- [[CopyFile]]
31+
32+---
33+*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).*

Back to history