Functions Delphi

function InputBox ( const Caption, Prompt, Default : string ) : string;


Description
The InputBox 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. A Default value is displayed in the text box.

If the user presses OK, the default or user entered data is stored in the return string, otherwise an empty string is returned.

If the user cancels the dialog, then the return value is an empty string.

Use to ask the user for a data value, where you can give a sensible default value, to save the user unnecessary typing.

Related commands
InputQuery Display a dialog that asks for user text input
PromptForFileName Shows a dialog allowing the user to select a file
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

Example code : Keep asking the user for their city with a default
var
value : string;
begin
// Keep asking the user for their town
repeat
value := InputBox('Test program', 'Please type your town', 'Cardiff');
until value <> '';
// Show their name
ShowMessage('Your town is '+value);
end;

Show full unit code
A dialog is displayed asking for the user city,
with Cardiff given as the initial value.

If the user just hits OK, then :

Your town is Cardiff

is then displayed