RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
Dialogs.InputQuery Function

Displays an input dialog box that lets the user enter a string, double, or integer.

Pascal
function InputQuery(const ACaption: string; const APrompt: string; var Value: string): Boolean;
C++
Boolean InputQuery(const AnsiString ACaption, const AnsiString APrompt, AnsiString Value);

Call InputQuery to bring up an input dialog box ready for the user to enter a string, double, or integer in its edit box. 

ACaption is the caption of the dialog box. 

APrompt is the text that prompts the user to enter input in the edit box. 

Value is the value that appears in the edit box when the dialog box first appears and which returns the value that the user enters. 

InputQuery returns true if the user chooses OK, and false if the user chooses Cancel or presses the Esc key. 

If a default value should be used when the user cancels out of the dialog, use InputBox instead.  

C++ Examples: 

 

/*
This example uses a button and a label on the form. When the
user clicks the button, the input box displays. If the user
chooses OK, the string that appears in the edit box of the
dialog box displays as the caption of the label on the form.
If the user chooses Cancel, the dialog box closes and the
caption of the label remains unchanged.
*/
#include <dialogs.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  UnicodeString NewString = "Default String";
  if (InputQuery("Input Box", "Prompt", NewString))
    // NewString has been changed by the user, who clicked ok
    Label1->Caption = NewString;
}

 

Delphi Examples: 

{
This example uses a button and a label on the form. When the
user clicks the button, the input box displays. If the user
chooses OK, the string that appears in the edit box of the
dialog box displays as the caption of the label on the form.
If the user chooses Cancel, the dialog box closes and the
caption of the label remains unchanged.
} 
procedure TForm1.Button1Click(Sender: TObject);
var
  NewString: string;
  ClickedOK: Boolean;
begin
  NewString := 'Default String';
  ClickedOK := Dialogs.InputQuery('Input Box', 'Prompt', NewString);
  if ClickedOK then            { NewString contains new input string }
    Label1.Caption := NewString;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!