[Lazarus] Why is TCustomControl.Canvas public?

Flávio Etrusco flavio.etrusco at gmail.com
Thu Jul 14 02:03:31 CEST 2011


On Wed, Jul 13, 2011 at 8:37 PM, Luiz Americo Pereira Camara
<luizmed at oi.com.br> wrote:
> On 13/7/2011 05:42, Flávio Etrusco wrote:
>>
>> Hello,
>> Wouldn't it better to make Canvas protected and pass it on the OnPaint
>> event?
>
> Yes. It seems a Delphi compatible design

I guess you mean the current behavior is as it is for Delphi
compatibility, right?
I supposed so, but isn't it worth changing?


>>  and I don't even
>> remember Delphi having OnPaint in TCustomControl,
>
> Yes Delphi does not has.
>
> IMHO it does not makes sense since TCustomControl is not supposed to be used
> directly. It's supposed to be derived and override Paint. The same for
> SetColor. Color should not be public so not handled by default in
> TCustomControl.

I kind of agree; that must be the reasoning for Borland.
OTOH I realize it can be quite useful for quick hacks, like painting a
background image. It'd be even more useful there pre- and post- events
hardcoded in PaintWindow. I vote for Painting and Paint, respectively
;-)


>> but...
>> BTW why is OnPaint called inside TCustomControl.Paint instead of
>> TCustomControl.PaintWindow?
>
> PaintWindow -> Paint -> OnPaint
>
> Luiz
>

I know, but it'd be better be invoked by/in PaintWindow so that all
controls have consistent behavior and component implementors don't
have to remember to call 'inherited'.

-Flávio




More information about the Lazarus mailing list