DelphiBasics
InputQuery
Function
Display a dialog that asks for user text input Dialogs unit
 function InputQuery(const Caption, Prompt string; var UserValue string):Boolean;
Description
The InputQuery function displays a simple dialog box with the given Caption and Prompt message. It asks the user to enter data in a text box on the dialog.
 
If the user presses OK, the entered data is stored in the UserValue variable and the return value is True.
 
If the user cancels the dialog, then the return value is False and any entered data is lost.
 
Use to ask the user for simple data such as a name.
Related commands
InputBoxDisplay a dialog that asks for user text input, with default
PromptForFileNameShows a dialog allowing the user to select a file
ShowMessageDisplay a string in a simple dialog with an OK button
ShowMessageFmtDisplay formatted data in a simple dialog with an OK button
ShowMessagePosDisplay a string in a simple dialog at a given screen position
 Download this web site as a Windows program.




 
Example code : Keep asking the user for their name until they do so
var
  value : string;

begin
  // Keep asking the user for their name
  repeat
    if not InputQuery('Test program', 'Please type your name', value)
    then ShowMessage('User cancelled the dialog');
  until value <> '';

  // Show their name
  ShowMessage('Hello '+value);
end;
Show full unit code
  A dialog is displayed asking for the user name.
  If the user types their name, 'Fred' and hits OK :
  
  Hello Fred
  
  is then displayed
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page