Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-07

Why is TCustomControl.Canvas public?

9 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Flávio Etrusco

Hello,
Wouldn't it better to make Canvas protected and pass it on the OnPaint event? I'm almost sure is was also public in Delphi, and I don't even remember Delphi having OnPaint in TCustomControl, but... BTW why is OnPaint called inside TCustomControl.Paint instead of TCustomControl.PaintWindow?

Best regards,
Fl?vio

Reply by email

Luiz Americo Pereira Camara
to Flávio Etrusco
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'm almost sure is was also public in Delphi,

Yes it is.

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.

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

PaintWindow -> Paint -> OnPaint

Luiz

Reply by email

Flávio Etrusco
to Luiz Americo Pereira Camara: Yes. It seems a Delphi compatible design Yes it is. Yes Delphi does not has. IMHO it does…
Luiz Americo Pereira Camara wrote 7 lines
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?

Show quoted text 9 lines
> ?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 ;-)

Show quoted text 8 lines
> 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

Reply by email

Luiz Americo Pereira Camara
to Flávio Etrusco
Fl?vio Etrusco wrote 6 lines
> 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,

TCustomControl is to be a base class not for quick hacks. Adding more functions would blow the code for most components that don't use it

OnPaint can be even undesired in some controls

If some descendants needs OnPaint is pretty simple to add with the benefit of choosing where to call.

As an example see
http://code.google.com/p/luipack/source/browse/trunk/cairo/lcl/cairolcl.pas#86

OnPaint and SetColor are not necessary here just blow code

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 ;-)

I would keep a lean base class. Even i would remove onpaint and setcolor altogether

Anyway, since TCustomControl is not a visual control and you need those features, you can create easily an descendant and use it as base for your components

Luiz

Reply by email

Flávio Etrusco
to Luiz Americo Pereira Camara
(...) TCustomControl is to be a base class not for quick hacks. Adding more functions would blow the code for most components that don't use it

Oh my. I suppose it's not be used directly in TCustomControl, but on descendants.

OnPaint can be even undesired in some controls If some descendants needs OnPaint is pretty simple to add with the benefit of choosing where to call.

This is not in question. It's already there.

-Fl?vio

Reply by email

Felipe Monteiro de Carvalho
to Flávio Etrusco: On Wed, Jul 13, 2011 at 8:37 PM, Luiz Americo Pereira Camara I guess you mean the current…

2011/7/14 Fl?vio Etrusco :

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

No, there are many component sets which work with both the VCL and the LCL. Creating incompatibilities generates problems for component developers. Note that TCustomControl is a basic building block for component developers.

Making things that are protected in Delphi public in Lazarus is not a problem, but the opposite is a big compatibility problem.

Felipe Monteiro de Carvalho

Reply by email

Luiz Americo Pereira Camara
to Flávio Etrusco: Oh my. I suppose it's not be used directly in TCustomControl, but on descendants. This is…
Fl?vio Etrusco wrote 6 lines
> (...) > TCustomControl is to be a base class not for quick hacks. Adding more > functions would blow the code for most components that don't use it Oh my. I suppose it's not be used directly in TCustomControl, but on descendants.

What about descendants that dont use it? Dont need it?

Show quoted text 6 lines
> OnPaint can be even undesired in some controls > > If some descendants needs OnPaint is pretty simple to add with the benefit > of choosing where to call. This is not in question. It's already there.

Yes but is useless. Even delphi does not has.

For an descendant overriding Paint is easier then assigning an OnPaint handler. And the descendant may not want to expose OnPaint to users case when will just be using extra memory

Luiz

Reply by email

Flávio Etrusco
to Felipe Monteiro de Carvalho: 2011/7/14 Fl?vio Etrusco : No, there are many component sets which work with both the VCL…
Felipe Monteiro de Carvalho wrote 16 lines
2011/7/14 Fl?vio Etrusco : > I guess you mean the current behavior is as it is for Delphi > compatibility, right? > I supposed so, but isn't it worth changing? No, there are many component sets which work with both the VCL and the LCL. Creating incompatibilities generates problems for component developers. Note that TCustomControl is a basic building block for component developers. Making things that are protected in Delphi public in Lazarus is not a problem, but the opposite is a big compatibility problem. -- Felipe Monteiro de Carvalho

Accessing Canvas outside Paint in Windows isn't recommended, but works. It doesn't on other platforms, and we've seen in the ML several people falling in this trap, didn't we?

-Fl?vio

Reply by email