1

Can someone please explain me which control is better to create custom componens? What is the difference between twincontrol and tcustomcontrol?

Thank you in advance

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Emre Acikgoz
  • 93
  • 1
  • 11

1 Answers1

9

Can someone please explain me which control is better to create custom componens?

That depends on what kind of component you are making and what its requires are.

Is it visual?

  • If no, use TComponent.

  • if yes, does it need its own HWND (input focus, window messages, etc)?

    • If no, use TGraphicControl.

    • If yes, does it need to custom paint itself?

      • if yes, use TCustomControl.

      • if no, use TWinControl.

What is the difference between twincontrol and tcustomcontrol?

TCustomControl is a TWinControl descendant that adds some additional handling for the WM_PAINT message, on top of what TWinControl does. TCustomControl exposes a public Canvas property that you can draw on. During painting, it enables the csCustomPaint flag in the ControlState property, and then calls a virtual Paint() method that your component can override. So the benefit of TCustomControl is that it makes custom painting a little easier to manage. Nothing more.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Thank you Remy Lebeau that is very good explanation for me, it gave me a really good understanding, can i ask what does a hwnd do for a component? Is it used for to get focus? – Emre Acikgoz Apr 23 '16 at 01:35
  • 1
    An `HWND` is a Win32 data type that represents a window. All UI controls at the OS level are windows and thus require an `HWND`. Yes, input focus is part of that system (but there is more to it than just that). Delphi takes things a step further by introducing *graphical* controls in addition to *windowed* controls. A graphical control lives inside of windowed control. As such, it is still visible to the user, and can even be clicked on, but cannot receive input focus from the OS. Only windowed controls can have focus. – Remy Lebeau Apr 23 '16 at 01:42