Working with components Index
Go Up to Programming with Delphi Index
Many components are provided in the integrated development environment (IDE) on the Tool Palette. You select components from the palette and drop them onto a form or data module. You design the application’s user interface by arranging the visual components such as buttons and list boxes on a form. You can also place nonvisual components such as data access components on either a form or a data module.
At first glance, Delphi components appear to be just like any other classes. But there are differences between components in Delphi and the standard class hierarchies that most programmers work with. Some differences are described here:
- All Delphi components descend from TComponent.
- Components are most often used "as is" and are changed through their properties, rather than serving as "base classes" to be subclassed to add or change functionality. When a component is inherited, it is usually to add specific code to existing event handling member functions.
- Components can only be allocated on the heap, not on the stack.
- Properties of components intrinsically contain run-time type information.
- Components can be added to the Tool Palette in the IDE and manipulated on a form.
Components often achieve a better degree of encapsulation than is usually found in standard classes. For example, consider the use of a dialog containing a push button. In a Windows program developed using VCL components, when a user clicks on the button, the system generates a WM_LBUTTONDOWN message. The program must catch this message (typically in a switch statement, a message map, or a response table) and dispatch it to a routine that will execute in response to the message.
Most Windows messages (VCL) are handled by Delphi components. When you want to respond to a message, you only need to provide an event handler.
- Setting Component Properties
- Calling Methods
- Working with Events and Event Handlers
- Adding Custom Components to the Tool Palette