Take Away: InputBox allows you to set a value, display it to the user, and have the user change it. Although InputBox generally isn’t flashy enough for finished applications, it is great for debugging and smaller “in-house” applications.
Add a button to our form (set its Caption to InputBox).
Double click on the button to bring up the editor.
Add lines 2, 3, 5, and 6 from the code listing to it.
Run and test the program.
Notes:
Notice we used to the “+” symbol to concatenate two strings (a literal and a variable).
Because themethod Button4Click belongs to the class TForm1, the first line must include both to uniquely identify the method. You’ll learn a lot more about object oriented programming as you learn Delphi. For now, this simple definition will work.
Code Listing
1. procedure TForm1.Button4Click(Sender: TObject);
2. var
3. sAns : String;
4. begin
5. sAns := InputBox('Question', 'What is you name?', 'Tiger Woods');
6. ShowMessage('Hello ' + sAns);
7. end;