Simple data input
You can use a simple edit box (tool-tip TEdit) to enter data, but you would need to add a label to inform the user what to put in it. A labelled edit positions conveniently a label next to the edit box. The steps to output the text in a labelled edit box to a separate label on a form are as follows:
- Create a new application and save the unit as uGreetUser.pas and the project as GreetUser.dpr.
- Open the form and add a label (tool-tip TLabel ) and button (tool-tip TButton) from the Standard tab of components and a labelled edit (tool-tip TLabeledEdit) from the Additional tab.
- Rename the components by changing in the Object Inspector the Name properties of the form, label, button and labelled edit to frmGreeting, lblGreeting, btnGreeting and leForename, respectively.
- Using the Object Inspector, change the Caption property of the form, label, and button to Greeting, blank (by deleting the contents), and Greet me, respectively.
- Using the Object Inspector for the labelled edit, click on the + to the left of EditLabel then change the caption of the EditLabel to Enter forename then press button.
Double click on the button in the form to create the procedure TfrmGreeting.btnGreetingClick(Sender: Tobject) then enter between begin and end the three lines:
lblGreeting.Font.Color := clRed; lblGreeting.Caption := 'Hello ' + leForename.text + '!'; leForename.text := '';
- Resize the form and position the components to your satisfaction.
Run the program to obtain:
Labelled edit box for data input
Using string data from an edit box
Button component used
Meaningful names given to components