Sign in Join
Wiki copytemporary

Revision 3 of 3, by WikiArchive on 11-9-2026. The page as it is now.

Howto Use TOpenDialog

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.

pascal
[![Component Palette Dialogs.png](/wiki-images/7/72/Component_Palette_Dialogs.png)](</File: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:

pascal
procedure TForm1.FormCreate(Sender: TObject);
    begin
      OpenDialog1.InitialDir := 'C:\';
      OpenDialog1.Filter := 'Binary files (*.bin;*.hex)|*.bin;*.hex|Text Files (*.txt)|*.txt|All Files (*.*)|*.*';
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if OpenDialog1.Execute then
        begin
          if fileExists(OpenDialog1.Filename) then
            ShowMessage(OpenDialog1.Filename);
        end
      else
        ShowMessage('No file selected');
    end;

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.

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.

See also


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.