The Input Query Request



Like the InputBox() function, the InputQuery() function is used to display a prompting dialog box to the user. The syntax of this function is:

function InputQuery(const ACaption: string;
		    const APrompt: string;
		    var Value: string): Boolean;

This takes three strings. The ACaption parameter is a string that displays on the title bar of the dialog box. The APrompt parameter is the sentence that indicates to the user what to type in the edit box. Like the InputBox() function, the Value parameter provides a default and sample value to the user. Like the InputBox() function, the user can type a new value.

Here is an example of calling the InputQuery() function:

procedure TForm1.btnMessageBoxClick(Sender: TObject);
var Value : String;
    InputQuery('Exiting Application',
	       'Are you sure you want to exist (y=Yes/n=No)?',

This would produce:

Input Query

Unlike the InputBox() function that returns a string, the InputQuery() function returns two values. By its declaration, this function returns a Boolean value of true or false. If the user clicks OK or presses Enter after using the dialog box, the function returns true. If the user presses Esc or clicks Cancel, the function returns false.

If the user clicks OK (or presses Enter), like the InputBox() function, whether the user had changed the value of the text box or not, the content of the text box, provided as the Value argument, would be returned. Because the Value argument is passed by reference, the function can return two values. If the user clicks Cancel (or presses Esc) after dealing with the dialog box, the value of the Value argument would be ignored.

You can validate the returned Value by writing a conditional statement that examines whether the user had clicked OK or Cancel. In the following example, when the user clicks a button on the form, the compiler finds out if the user had clicked OK:

procedure TForm1.btnMessageBoxClick(Sender: TObject);
var Answer : String;
    if InputQuery('Exiting Application',
		   'Are you sure you want to exist (Yes/No)?',
		   Answer) = True then
	ShowMessage('Your answer was ' + Answer)

Here is an example of running the program:

Input Query

Message Box


Home Copyright © 2010 FunctionX, Inc.