RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
Dialogs.InputBox Function

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

Pascal
function InputBox(const ACaption: string; const APrompt: string; const ADefault: string): string;
C++
AnsiString InputBox(const AnsiString ACaption, const AnsiString APrompt, const AnsiString ADefault);

Dialogs

Call InputBox 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. 

ADefault is the value that appears in the edit box when the dialog box first appears. 

AMin is the minimum value the user can enter into the edit box. 

AMax is the maximum value the user can enter into the edit box. 

Decimals does nothing. 

Increment controls the amount by which the value in the spin control changes when the user clicks the up or down arrow. (It has no effect on values that the user types). 

If the user chooses the Cancel button, InputBox returns the default value. If the user chooses the OK button, InputBox returns the value in the edit box. 

Use the InputBox function when there is a default value that should be used when the user chooses the Cancel button (or presses Esc) to exit the dialog. If the application needs to know whether the user chooses OK or Cancel, use the InputQuery function instead.  

C++ Examples: 

 

/*
This example displays an input dialog box when the user
clicks a button on the form. The input dialog box includes a
prompt string and a default string. The string the user enters
in the dialog box is stored in the InputString variable and
the text edit.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  AnsiString InputString = InputBox("Input Box", "Prompt", "Default string");
  Edit1->Text = InputString; 
}

 

Delphi Examples: 

{
This example displays an input dialog box when the user
clicks a button on the form. The input dialog box includes a
prompt string and a default string. The string the user enters
in the dialog box is stored in the InputString variable and
the text edit.
}

procedure TForm1.Button1Click(Sender: TObject);
var
  InputString: string;
begin
  InputString:= Dialogs.InputBox('Input Box', 'Prompt', 'Default string');
  Edit1.Text:= InputString;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!