Tuesday, 26 September 2017

VCL Hierarchy in Delphi: Types of Controls in Delphi: TWinControls and TGraphicControls

In VCL (Visual Component Library) hierarchy, you will find TObject at the top, then TPersistent, then TComponent and then TControl.

TObject >> TPersistent >> TComponent >>TControl

VCL Hierarchy in Delphi
TObject is the base class from which all classes descend.

TPersistent class descends directly from TObject. The special characteristic of TPersistent is that it is an abstract class that defines the methods that allow it to be streamed.

TComponent is the base class from which all components descend. Non-visual components are descendants of TComponent. For example: TTimer

TControl is the base class from which all the visual components descend. For example: TEdit, TListBox, TComboBox etc.

Again, there are two types of controls (TControl): Window Controls (TWinControl) and Graphic Controls (TGraphicControl)

Following is the difference between TWinControl and TGraphicControl in Delphi:

TWinControls

TWinControls can receive input focus and they can be parents to other controls.

Example: TEdit, TListBox and TComboBox

TGraphicControl

TGraphicControls differ from TWinControls in that they cannot receive input focus. Also, they cannot be parents to other controls.

Example: TLabel

TGraphicControls are used when you want to display something on the form.

Two key advantages of TGraphicControls over TWinControls:

1. TGraphicControls don't use up system resources since they don't require a window handle.

2. They are a bit faster at drawing than their TWinControl counterparts since their painting is not subject to the windows message dispatching system. Instead, they piggyback on their parent's paint process.

For more details, please refer to documentation.

No comments:

Post a Comment