Shows a dialog allowing the user to select a file Dialogs unit
 function PromptForFileName ( var FileName : string; { const Filter : string; const DefaultExt : string;  const Title : string; const InitialDir : string; SaveDialog : Boolean = False } ) : Boolean;
The PromptForFileName function presents a dialog to the user allowing navigation to, and selection of a file.
If the user presses OK the FileName variable is updated with the full drive/path/filename value for the selected file, and the return value is True.
If the user presses Cancel, no updates are done, and the return value is False.
The remaining parameters are all optional (although parameters used on the right mandate use of the preceding parameters) :
Used to limit the types of file displayed. The format is as follows :
For example, to show only .txt and .pas files :
Text files (*.txt)|*.txt|Delphi files (*.pas)|*.pas
Used to define an extension to add to a new file name (if SaveDialog is True).
Used to give a title to the dialog.
Positions the dialog at a given directory. For example :
'C:Program Files'
Determines whether a new file can be selected for saving.
Related commands
InputBox Display a dialog that asks for user text input, with default
InputQuery Display a dialog that asks for user text input
ShowMessage Display a string in a simple dialog with an OK button
ShowMessageFmt Display formatted data in a simple dialog with an OK button
ShowMessagePos Display a string in a simple dialog at a given screen position
TOpenDialog Displays a file selection dialog
TSaveDialog Displays a dialog for selecting a save file name
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Use this dialog to select a text file
  selectedFile   : string;

  // Ask the user to select a file
  if PromptForFileName(selectedFile,
                       'Text files (*.txt)|*.txt',
                       'Select your project file',
                       False)  // Means not a Save dialog
    // Display this full file/path value
    ShowMessage('Selected file = '+selectedFile)
    ShowMessage('Cancel pressed');
Show full unit code
   { In the dialog, user selects C:\Files\data.txt and hits OK }
   Selected file = C:\Files\data.txt
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page