Difference between revisions of "Howto Use TOpenDialog"

From Lazarus wiki
Jump to navigationJump to search
m (Added Close to avoid error message if Cancel is clicked.)
(Undo revision 107399 by Windsurfer (talk) If you met error then write at forum and if it is really a bug then write bugreport at bugtracker.)
Line 15: Line 15:
 
   filename := OpenDialog1.Filename;
 
   filename := OpenDialog1.Filename;
 
   ShowMessage(filename);
 
   ShowMessage(filename);
end else
 
  OpenDialog1.Close // This avoids an error message in Laz 1.6.3 (fixes) if user clicks on Cancel.
 
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 08:14, 20 February 2017

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

Howto Use TOpenDialog

Simple and short guideline:

  1. Place a TOpenDialog widget topendialog.png on your form (anyplace, since it will be not visible).
  2. 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.

See also