Problem: An example of using an Edit Box to accept user input with Delphi. Solution: EDIT BOX (Accepting User Input) Wayne Shaddock October 2, 1998 This demo uses: A TForm A TButton A TEdit 2 TLabel It demonstrates the use of an edit box to take input from the console and display to the user some information about the input data. 1. Open a new project. 2. From the Standard tab on the Component Palette place a button, 2 labels, and an edit box on the form. 3. Arrange the components as desired. (The first label will display some instructions when the button is clicked so it should be placed above the edit box. The second label will give information about the user's input, so it should be placed below or to the right of the edit box) 4. Double click the button to create an event handler and type in the following code in the body of the Button1.Click procedure: Label1.Caption := 'Enter an integer'; 5. Double-click the edit box and create a variable declaration section right befor the body of the procedure. Declare the following variable: X : Integer; 6. Type the following code in the body of the Edit1.Change procedure: X := StrToInt(Edit1.Text); if X> 10 then Label2.Caption := 'You entered a number greater than 10' else if X <= 10 then Label2.Caption := 'You entered a number less than or equal to 10'; 7. Click the 'Run' arrow on the toolbar to compile and run the program.
Last Modified: 23-OCT-00