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:

  1. Create a new application and save the unit as uGreetUser.pas and the project as GreetUser.dpr.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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 := '';
  7. Resize the form and position the components to your satisfaction.
  8. Run the program to obtain:


Features introduced:
  • Labelled edit box for data input

  • Using string data from an edit box

  • Button component used

  • Meaningful names given to components

Programming - a skill for life!

How to set up Lazarus to create, edit and run form-based Object-Pascal applications