Programming Delphi TControl, TWinControl and TWidgetControl Components in Delphi/C++Builder

The TControl Branch.

The TControl branch consists of components that descend from TControl but not TWinControl (TWidgetControl in CLX). Objects in this branch are controls that are visual objects that the application user can see and manipulate at runtime. All controls have properties, methods, and events in common that relate to how the control looks, such as its position, the cursor associated with the control's window (or widget in CLX), methods to paint or move the control, and events to respond to mouse actions. Controls can never receive keyboard input.

Whereas TComponent defines behavior for all components, TControl defines behavior for all visual controls. This includes drawing routines, standard events, and containership.
All visual controls share certain properties. While these properties inherited from TControl, they are published梐nd hence appear in the Object Inspector--only for components to which they are applicable. For example, TImage does not publish the Color property, since its color is determined by the graphic it displays.

There are two types of controls:

  • Those that have a window (or widget) of their own.
  • Those that use the window (or widget) of their parent.

Controls that have their own window are called "windowed" controls (VCL) or "widget-based" controls (CLX) and descend from TWinControl (TWidgetControl in CLX). Buttons and check boxes fall into this class. See TWinControl branch for details on windowed controls.
Controls that use the window (or widget) of their parent are called graphic controls and descend from TGraphicControl. Images and shapes fall into this class. Graphic controls do not maintain a handle and cannot receive the input focus. Because a graphic control does not need a handle, it uses fewer system resources. Graphic controls must draw themselves and cannot be a parent to other controls.

See graphics controls.

TWinControl and TWidgetControl Branch.

In the VCL, the TWinControl branch includes all controls that descend from TWinControl. TWinControl is the base class for all windowed controls, which are items that you will use in the user interface of an application, such as buttons, labels, and scroll bars. Windowed controls are wrappers around a Windows control.
In CLX, TWidgetControl, which replaces TWinControl, is the base class for all widget controls, which are wrappers around widgets.

Windowed and widget controls:

  • Can receive focus while an application is running, which means they can receive keyboard input from the application user. In comparison, other controls may only display data.
  • Can be a parent of one or more child controls.
  • Have a handle, or unique identifier.

The TWinControl/TWidgetControl branch includes both controls that are drawn automatically (including TEdit, TListBox, TComboBox, TPageControl, and so on) and custom controls that C++Builder must draw, such as TDBNavigator, TMediaPlayer (VCL only), and TGauge (VCL only). Direct descendants of TWinControl/TWidgetControl typically implement standard controls, like an edit field, a combo box, list box, or page control, and, therefore, already know how to paint themselves.

The TCustomControl class is provided for components that require a window handle but do not encapsulate a standard control that includes the ability to repaint itself. You never have to worry about how the controls render themselves or how they respond to events--C++Builder completely encapsulates this behavior for you.

Add comment

Security code

Programming - Delphi