1. Home
  2. Computing & Technology
  3. Delphi Programming
Learn about: properties, events and Delphi Pascal
Page 1: Placing Components on a Form
 More of this Feature
• Page 2: Properties and Event Handlers
 Join the Discussion
"Post your views and comments to this chapter of the free Delphi Programming Course"
Discuss!
 Related Resources
• A Beginner's Guide to Delphi Programming.TOC

Welcome to the fourth chapter of the FREE online programming course:
A Beginner’s Guide to Delphi Programming.
Create your second simple Delphi application allowing you to learn hot to place components on a form, set their properties, write event handler procedures to make components cooperate together.

   Creating your second Delphi Application
In the previous chapter we have created a simple Delphi application without going into details of the Object Pascal language behind all Delphi projects. This time, our task is to create a more complex application that involves several Delphi components - again, the application will be pretty simple. The idea is to help you understand the Delphi Pascal source and how components operate and communicate with their properties, methods and events.

To start, run Delphi. As explained, when you run Delphi a new project (application) is created with one blank form.

   Placing Components on a Form
All forms of a Delphi application have one or more components. Components, or objects, usually display information or allow the user to perform an action. For example a Label is used to display static text, an Edit box is used to allow user to input some data, a Button can be used to initiate actions.
Any combination of components can be placed on a form, you should remember that Windows is even-driven, while your application is running a user can interact with any component on a form, it is your task, as a programmer, to decide what happens when a user clicks a button or changes a text in an Edit box.

As stated before, Delphi supplies a number of components for you to create complex user interfaces. You can find all the components you can place on a form on the Component palette. To place a component on a form, locate its icon on the Palette and double-click it. This action places a component on the active form. Visual representation of most components is set with their set of properties. When you first place a component on a form, it is placed in a default position, with default width and height. You can change the size and position later, by using the Object Inspector.

Note: to remove a component from a form, click on it and press the [Del] key. Later, in this Course, I'll explain what happens to code (if some exists) associated with the component.

Your second Delphi application
We can now start adding components to a form. Activate the only form in a project, point to the Component palette and select the "Standard" tab. We will add three standard Windows components and write some example code to see how components work together.

VCL standard palette

Double click the following three components:

  • TLabel : use this component when you want to add some text to a form that the user can't edit.
  • TEdit : standard Windows edit control. Edit controls are used to retrieve text that users type.
  • TButton : use this component to put a standard push button on a form.

    Using drag-and-drop to rearrange the components to appear on a form similar to:

    A sample Delphi form

    Note: even though at this stage of the Course, it is not important to create "nicely looking" user interfaces, I strongly encourage you to always try to arrange components on form so they create a user friendly interface. Here are some suggestions and Standards of Screen Design.

    Next page > Changing Component Properties; Writing Code - Events and Event Handlers > Page 1, 2

    A Beginner's Guide to Delphi Programming: Chapter 5 >>
    >> Understanding the Delphi unit source

  • Explore Delphi Programming
    About.com Special Features

    Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

    Easy ways to connect two computers for networking purposes. More >

    1. Home
    2. Computing & Technology
    3. Delphi Programming

    ©2009 About.com, a part of The New York Times Company.

    All rights reserved.