I create my own control class. It is to be available for Lazarus and Delphi. Basically, it is ported from Delphi and expanded a bit. Currently I use:
- operating system: Windows 10,
- Lazarus 2.2.4 64-bit,
- Delphi 12 Prof.
To make the most of what the libraries provide (VCL and LCL, respectively), I based my class on the TCustomControl class. Unfortunately, there is one problem. In the LCL library, the TCustomControl class has an OnPaint event added, which is public (maybe it was supposed to be published, but someone made a mistake?). However, in the VCL library (Delphi), the TCustomControl class does not have this event. To better illustrate this issue, I present the definitions of this class in both libraries below.
Definition of the TCustomControl class in the VCL library (Delphi):
TCustomControl = class(TWinControl)
private
FCanvas: TCanvas;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
protected
procedure Paint; virtual;
procedure PaintWindow(DC: HDC); override;
{$IF NOT DEFINED(CLR)}
property Canvas: TCanvas read FCanvas;
{$ENDIF}
public
{$IF DEFINED(CLR)}
function get_Canvas: TCanvas;
property Canvas: TCanvas read get_Canvas;
property Color;
{$ENDIF}
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
Definition of the TCustomControl class in the LCL library (Lazarus):
TCustomControl = class(TWinControl)
private
FCanvas: TCanvas;
FOnPaint: TNotifyEvent; // <- an event that is not in the VCL
protected
class procedure WSRegisterClass; override;
procedure WMPaint(var Message: TLMPaint); message LM_PAINT;
procedure DestroyWnd; override;
procedure PaintWindow(DC: HDC); override;
procedure FontChanged(Sender: TObject); override;
procedure SetColor(Value: TColor); override;
procedure Paint; virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
public
property Canvas: TCanvas read FCanvas write FCanvas;
property BorderStyle;
property OnPaint: TNotifyEvent read FOnPaint write FOnPaint; // <- an event that is not in the VCL
end;
The class I am creating does not need the OnPaint event. Moreover, once installed in the IDE, the user would be misled to see this event. He would be even more surprised to find that this event is not used. The OnPaint event should not be present in the TCustomControl class. There should be a separate class for this purpose.
I understand that there are people who may use this event, but in such a situation there should be two classes:
-
TCustomControl, behaving similarly to the one in VCL,
-
TPaintWinControl, which would be a window control with drawing capabilities like in TPaintBox.
The question for people supervising the work on the LCL foundation is as follows: is there a chance to change the definition of the TCustomControl class?
If there is no chance for change, then too bad. I will have to create my own base class, similar to TCustomControl but without the OnPaint event. The problem is that there will be a lot of conditional compilation directives for Delphi and Lazarus in the code. And this is not the only class I create that is based on TCustomControl.