Howto Use TOpenDialog

From Free Pascal wiki
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Deutsch (de) English (en) español (es) suomi (fi) français (fr) 日本語 (ja) polski (pl) русский (ru) slovenčina (sk)

Simple and short guidelines:

1. Place a TOpenDialog widget topendialog.png on your form. It can be placed anywhere on your form as it is not visible during program run time but only during design time.

Component Palette Dialogs.png 

It is located in the Dialogs tab of the component palette and is the leftmost component.

2. In your code write something similar to:

if OpenDialog1.Execute then
  begin
    if fileExists(OpenDialog1.Filename) then
      ShowMessage(OpenDialog1.Filename);
  end
else
  ShowMessage('No file selected');

The dialog Execute method displays the file open dialog. It returns true when user has selected a file, false when user has aborted.

The dialog Filename property returns the full filename including drive and path.

Light bulb  Note: This control only collects the filename. It does not actually open the file. Your code must do that.

See also