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 |
// Full Unit code. // ----------------------------------------------------------- // You must store this code in a unit called Unit1 with a form // called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); 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; end.
|
Hide 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
|
|