Chapter 24: Component Development Essentials


Overview

There are a number of reasons for creating new components. You might want to create a new component to encapsulate and reuse an important piece of code, to enhance an existing component, in order to gain profit and prestige, or even when the sole purpose of creating a component is pure and simple fun. Whatever the reason, this chapter (and the following two chapters) will try to give you all the information you need to successfully create components.

From a theoretical standpoint, it's extremely easy to create a new component, given that you know how to create a new class:

type   TMyClass = class(TObject)   end;

In order to create a component that can be used in the IDE, you have to derive the new class from the ultimate ancestor of all components: the TComponent class or any of its descendants:

type   TMyComponent = class(TComponent)   end;

The TComponent class has the following traits:

  • It can be added to the Tool Palette.

  • It can be dropped on the Designer Surface and manipulated at design time.

  • It can own other components and manage them at run time.

  • It is a persistent object, meaning that it has the ability to save and load its properties to and from a DFM file (the TComponent class inherits this ability from the TPersistent class).

Components that inherit directly from the TComponent class (like the main menu and the common dialogs) are nonvisual components that have no user interface and are, at design time, displayed as an icon.



Inside Delphi 2006
Inside Delphi 2006 (Wordware Delphi Developers Library)
ISBN: 1598220039
EAN: 2147483647
Year: 2004
Pages: 212
Authors: Ivan Hladni

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net