Ancestor Classes


After you've made the decision to create a new component, you still have to decide the class from which you need to derive your new component. You can find out which class you need to derive from by answering these simple questions:

  1. Should the component be available at design time?

    If you want to use the component at design time, you have to derive your component from TComponent or one of its descendants. If you don't need to use the component at design time, you shouldn't create a component. A better solution in this case is to derive a new class from TObject.

  2. Is it a nonvisual component like the TMainMenu and the TXPManifest components?

    If you need a component that lacks a user interface but needs to be available at design time, you should derive it from TComponent. If you need a visual component, you should derive your new component from TControl or, better yet, from one of TControl's descendant classes.

  3. Should the new component be a visual component (a control)?

    If you need to create a new control, you can choose between the TGraphicControl and TCustomControl classes. By deriving your component from TGraphicControl, you are creating a graphic control. By deriving your component from TCustomControl, you are creating a windowed control.

    Graphic controls are lightweight controls. They use fewer system resources than windowed controls and are able to respond to mouse events. However, graphic controls have no window handle and therefore cannot be passed to API functions, cannot respond to keyboard events, cannot receive focus, and cannot respond to Windows messages.

    Windowed controls, unlike graphic controls, have a window handle that makes them much more powerful than graphic controls. The window handle allows windowed controls to be passed to API functions, to receive input focus and keyboard events, to respond to Windows messages, and even to contain other windowed and graphic controls.

  4. Should the new component be a completely new component or a customized version of an existing one?

    If you want to create a completely new component, you should use the TComponent, TGraphicControl, or TCustomControl class as the ancestor class. But if you want to customize an existing component, it is best to derive your new component from the component you wish to customize. For instance, if you want to customize the behavior or appearance of the

    TListBox component, you can derive your new component from TListBox.

    The VCL also contains a number of TCustomComponentName components that can be used when you want to customize an existing component. For instance, you can use either the TListBox class or the TCustomListBox class to create a customized list box component. You can do this because the TCustomListBox and the TListBox components are essentially the same. The TListBox component is derived from the TCustomListBox component and the only difference between the two is that the TListBox component publishes all of TCustomListBox's properties, making them available in the Object Inspector at design time.



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