Difference between revisions of "Howto Use TOpenDialog"
From Lazarus wiki
Jump to navigationJump to searchLine 1: | Line 1: | ||
+ | |||
{{Howto Use TOpenDialog}} | {{Howto Use TOpenDialog}} | ||
− | |||
− | |||
Simple and short guideline: | Simple and short guideline: | ||
− | # Place a [[TOpenDialog]] widget [[image:topendialog.png]] on your form | + | # Place a [[TOpenDialog]] widget [[image:topendialog.png]] on your [[TForm|form]]. <br /> It can be placed anywhere as it is not visible during program [[runtime|run time]] but only during design time. <br \> [[Image:Component_Palette_Dialogs.png]] <br \> It is located on the [[Dialogs tab]] of the [[Component Palette|component palette]] and is the leftmost component <br /> |
# In your code write something similar to: | # In your code write something similar to: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang="pascal"> |
var | var | ||
filename: string; | filename: string; | ||
Line 18: | Line 17: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | The [[doc:lcl/dialogs/tcommondialog.execute.html | Execute]] method displays the file open dialog. It returns [[True|true]] when user has selected a file, [[False|false]] when user has aborted | + | The [[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. |
− | |||
− | |||
− | + | The [[doc:lcl/dialogs/tfiledialog.filename.html | Filename]] [[Property|property]] returns the full filename including drive and path. | |
+ | {{Note|This control only collects the filename. It does not actually open the file. Your code must do that.}} | ||
== See also == | == See also == | ||
* [[Howto Use TSaveDialog]] | * [[Howto Use TSaveDialog]] | ||
− | |||
− | |||
− | |||
− | |||
− |
Revision as of 20:26, 29 August 2019
│
Deutsch (de) │
English (en) │
español (es) │
suomi (fi) │
français (fr) │
日本語 (ja) │
polski (pl) │
русский (ru) │
slovenčina (sk) │
Simple and short guideline:
- Place a TOpenDialog widget on your form.
It can be placed anywhere as it is not visible during program run time but only during design time.
It is located on the Dialogs tab of the component palette and is the leftmost component - In your code write something similar to:
var
filename: string;
if OpenDialog1.Execute then
begin
filename := OpenDialog1.Filename;
ShowMessage(filename);
end;
The Execute method displays the file open dialog. It returns true when user has selected a file, false when user has aborted.
The Filename property returns the full filename including drive and path.
Note: This control only collects the filename. It does not actually open the file. Your code must do that.