Sign in Join
Wiki copytemporary

Howto Use TOpenDialog: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

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.
1+Simple and short guidelines:
42
5-```text
6-Image:Component_Palette_Dialogs.png
3+1\. Place a [[TOpenDialog]] widget [![topendialog.png](/wiki-images/1/1c/topendialog.png)](</File: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.
74```
8-
9-It is located in the [[Dialogs tab]] of the [[Component Palette|component palette]] and is the leftmost component.
5+[![Component Palette Dialogs.png](/wiki-images/7/72/Component_Palette_Dialogs.png)](</File:Component_Palette_Dialogs.png>)
6+```
107
11-2\. In your code write something similar to:
8+It is located in the [[Dialogs tab]] of the [[Component Palette|component palette]] and is the leftmost component.
129
13-``` pascal
14-if OpenDialog1.Execute then
15- begin
16- if fileExists(OpenDialog1.Filename) then
17- ShowMessage(OpenDialog1.Filename);
18- end
19-else
20- ShowMessage('No file selected');
10+2\. In your code write something similar to:
2111```
12+procedure TForm1.FormCreate(Sender: TObject);
13+ begin
14+ OpenDialog1.InitialDir := 'C:\';
15+ OpenDialog1.Filter := 'Binary files (*.bin;*.hex)|*.bin;*.hex|Text Files (*.txt)|*.txt|All Files (*.*)|*.*';
16+ end;
17+
18+ procedure TForm1.Button1Click(Sender: TObject);
19+ begin
20+ if OpenDialog1.Execute then
21+ begin
22+ if fileExists(OpenDialog1.Filename) then
23+ ShowMessage(OpenDialog1.Filename);
24+ end
25+ else
26+ ShowMessage('No file selected');
27+ end;
28+```
2229
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.
30+The dialog [ Execute](<http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/tcommondialog.execute.html> "doc:lcl/dialogs/tcommondialog.execute.html") [[Method|method]] displays the file open dialog. It returns [[True|true]] when user has selected a file, [[False|false]] when user has aborted.
2431
25-The dialog [[doc:lcl/dialogs/tfiledialog.filename.html|Filename]] [[Property|property]] returns the full filename including drive and path.
32+The dialog [ Filename](<http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/tfiledialog.filename.html> "doc:lcl/dialogs/tfiledialog.filename.html") [[Property|property]] returns the full filename including drive and path.
2633
27-> **Note:** This control only collects the filename. It does not actually open the file. Your code must do that.
34+![Light bulb](https://upload.wikimedia.org/wikipedia/commons/d/d8/Nuvola_apps_ktip.png) **Note:** This control only collects the filename. It does not actually open the file. Your code must do that.
2835
2936## See also
3037
31-- [[Howto Use TSaveDialog]]
32-- [[CopyFile]]
38+ * [[Howto Use TSaveDialog]]
39+ * [[CopyFile]]
3340
3441---
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).*
42+*From the Free Pascal wiki, page "Howto Use TOpenDialog", as the Internet Archive kept it on 2025-06-16, last changed on 2025-03-19. 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