Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Marc Weustink

Vincent Snijders wrote:

Graeme Geldenhuys schreef:

On 5/7/07, Vincent Snijders <[EMAIL PROTECTED]> wrote:


An advantage of having it public, is that you can pass a TControl to 
the widget
interface and it can access the Color property without resorting to 
cast to

decendants. I don't know if this technique is actually used though.



True, but where do you draw the line with such properties...? Many
others can fall in this category as well.




If you just subclass a class to access a protected property, then that 
property should not have been protected in the first place.


The whole fun of the design of the VCL and LCL with TCustom... is that 
you as developer have the choise to create a descendant of that 
component which hides some internal properties.
Unfortunately, this works agains us when accessing those protected 
properties from whithin the widgetset.
Since the widgetset is tight bound to the LCl, I don't consider access 
classes bad for accessing those protected properties. I see this as a 
kind of internal use.
By publishing those properties, you limit IMO the users of the 
TCustom... classes, since they cannot hide properties which they don't 
want to be exposed.
Therefore I think the Color property should go protected. An argument 
that public is easier for the widgetset classes in no argument to me.


Marc



Vincent

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives



_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Graeme Geldenhuys

On 5/7/07, Joao Morais <[EMAIL PROTECTED]> wrote:

> I agree...  And if you are going to use it often, create a local
> variable of the 'friend' class so you only need to cast once.

Not a good idea if you have inheritance:


True. I meant in a single function or small helper class, etc..


code. Anyway both fpc and lazarus team are doing an exceptional job
regarding compatibility.


Very true!


--
Graeme Geldenhuys

There's no place like S34° 03.168'  E018° 49.342'

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Joao Morais

Graeme Geldenhuys wrote:

On 5/7/07, Joao Morais <[EMAIL PROTECTED]> wrote:
> An advantage of having it public, is that you can pass a TControl to 
the

> widget interface and it can access the Color property without resorting
> to cast to decendants. I don't know if this technique is actually used
> though.

There are several properties where this feature would be welcome, eg
tcustomedit.text, tcustomcheckbox.checked, but you can use the following
workaround when necessary:

type
   tcustomeditfriend = class(tcustomedit);

...

tcustomeditfriend(edit).edit := 'value';



I agree...  And if you are going to use it often, create a local
variable of the 'friend' class so you only need to cast once.


Not a good idea if you have inheritance:

twincontrol
  control: twincontrolfriend

tcustomedit
  control: tcustomeditfriend

...

tcustomeditfriend.getcontrol
begin
  result := inherited control as tcustomeditfriend; // problem here
end;


I write many cross compiler (FPC and Delphi) code and keep breaking
the builds under Delphi due to the differences between LCL and VCL.


Yup. This is exactly my headackes. Cross FPC x Delphi and VCL x LCL 
code. Anyway both fpc and lazarus team are doing an exceptional job 
regarding compatibility.


--
Joao Morais

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Graeme Geldenhuys

On 5/7/07, Vincent Snijders <[EMAIL PROTECTED]> wrote:


Yes, and in this case, if I want to have access to the Color property 
(properly) in
the widgetset interfaces, the lowest visibility to accomplish that is public.



As because of that decision, no other component developers can hide
those properties? But making it Protected and using the
class-friendship (as Joao mentioned), you can still access those
properties in the widgetset AND allow component developers to surface
or hide the properties when needed.  The best of both worlds.  ;-)

I don't consider a friend-class a hack.  Do a quick Google search for
'friend class' and you will see that a lot a languages actually have
built-in support for it.

--
Graeme Geldenhuys

There's no place like S34° 03.168'  E018° 49.342'

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Vincent Snijders

Joao Morais schreef:
which should be necessary if you have the ownership of the source of 
tcustomchecbox.


Sorry?


... which should NOT be necessary ...

Vincent

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Joao Morais

Vincent Snijders wrote:

Joao Morais schreef:

Vincent Snijders wrote:
An advantage of having it public, is that you can pass a TControl to 
the widget interface and it can access the Color property without 
resorting to cast to decendants. I don't know if this technique is 
actually used though.


There are several properties where this feature would be welcome, eg 
tcustomedit.text, tcustomcheckbox.checked, but you can use the 
following workaround when necessary:


Which I consider a hack,


A hack or Object Pascal class-friendship?

which should be necessary if you have the 
ownership of the source of tcustomchecbox.


Sorry?

--
Joao Morais

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Vincent Snijders

Graeme Geldenhuys schreef:

On 5/7/07, Vincent Snijders <[EMAIL PROTECTED]> wrote:


If you just subclass a class to access a protected property, then that 
property

should not have been protected in the first place.



Well maybe the component developer wanted to hide that properties from
the end users of the component.  Making that property Public makes
that impossible. You cannot decrease visibility in descendant classes.
You can only increase visibility.  The rule of thumb (in Object
Pascal) has always been to start with the lowest visibility to
accomplish what you want and then increase visibility as needed.


Yes, and in this case, if I want to have access to the Color property (properly) in 
the widgetset interfaces, the lowest visibility to accomplish that is public.


Vincent

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Graeme Geldenhuys

On 5/7/07, Vincent Snijders <[EMAIL PROTECTED]> wrote:


If you just subclass a class to access a protected property, then that property
should not have been protected in the first place.



Well maybe the component developer wanted to hide that properties from
the end users of the component.  Making that property Public makes
that impossible. You cannot decrease visibility in descendant classes.
You can only increase visibility.  The rule of thumb (in Object
Pascal) has always been to start with the lowest visibility to
accomplish what you want and then increase visibility as needed.


--
Graeme Geldenhuys

There's no place like S34° 03.168'  E018° 49.342'

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Vincent Snijders

Graeme Geldenhuys schreef:

On 5/7/07, Vincent Snijders <[EMAIL PROTECTED]> wrote:


An advantage of having it public, is that you can pass a TControl to 
the widget
interface and it can access the Color property without resorting to 
cast to

decendants. I don't know if this technique is actually used though.



True, but where do you draw the line with such properties...? Many
others can fall in this category as well.




If you just subclass a class to access a protected property, then that property 
should not have been protected in the first place.


Vincent

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Graeme Geldenhuys

On 5/7/07, Vincent Snijders <[EMAIL PROTECTED]> wrote:


An advantage of having it public, is that you can pass a TControl to the widget
interface and it can access the Color property without resorting to cast to
decendants. I don't know if this technique is actually used though.



True, but where do you draw the line with such properties...? Many
others can fall in this category as well.


--
Graeme Geldenhuys

There's no place like S34° 03.168'  E018° 49.342'

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Graeme Geldenhuys

On 5/7/07, Joao Morais <[EMAIL PROTECTED]> wrote:


There are several properties where this feature would be welcome, eg
tcustomedit.text, tcustomcheckbox.checked, but you can use the following
workaround when necessary:

type
   tcustomeditfriend = class(tcustomedit);

...

tcustomeditfriend(edit).edit := 'value';



I agree...  And if you are going to use it often, create a local
variable of the 'friend' class so you only need to cast once.

I write many cross compiler (FPC and Delphi) code and keep breaking
the builds under Delphi due to the differences between LCL and VCL.
Luckily the Delphi developers are very lenient. :-)

I know not everything in the LCL would ever be 100% compatible to the
VCL, but we could strive to get it as compatible as possible.  That
would really help component developers with porting Delphi components
to Lazarus or developers as myself that maintain components which need
to compile under Lazarus and Delphi.

--
Graeme Geldenhuys

There's no place like S34° 03.168'  E018° 49.342'

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Graeme Geldenhuys

On 5/7/07, Joao Morais <[EMAIL PROTECTED]> wrote:

> An advantage of having it public, is that you can pass a TControl to the
> widget interface and it can access the Color property without resorting
> to cast to decendants. I don't know if this technique is actually used
> though.

There are several properties where this feature would be welcome, eg
tcustomedit.text, tcustomcheckbox.checked, but you can use the following
workaround when necessary:

type
   tcustomeditfriend = class(tcustomedit);

...

tcustomeditfriend(edit).edit := 'value';



I agree...  And if you are going to use it often, create a local
variable of the 'friend' class so you only need to cast once.

I write many cross compiler (FPC and Delphi) code and keep breaking
the builds under Delphi due to the differences between LCL and VCL.
Luckily the Delphi developers are very lenient. :-)

I know not everything in the LCL would ever be 100% compatible to the
VCL, but we could strive to get it as compatible as possible.  That
would really help component developers with porting Delphi components
to Lazarus or developers as myself that maintain components which need
to compile under Lazarus and Delphi.


--
Graeme Geldenhuys

There's no place like S34° 03.168'  E018° 49.342'

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Vincent Snijders

Joao Morais schreef:

Vincent Snijders wrote:
An advantage of having it public, is that you can pass a TControl to 
the widget interface and it can access the Color property without 
resorting to cast to decendants. I don't know if this technique is 
actually used though.


There are several properties where this feature would be welcome, eg 
tcustomedit.text, tcustomcheckbox.checked, but you can use the following 
workaround when necessary:


Which I consider a hack, which should be necessary if you have the ownership of the 
source of tcustomchecbox.


Vincent

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Joao Morais

Vincent Snijders wrote:

Graeme Geldenhuys schreef:

On 5/6/07, Michael Van Canneyt <[EMAIL PROTECTED]> wrote:


TControl non visual ?? How is that ? TLabel or TImage are very visual...
Non-windowed, you mean ?


Ah ok, I got it mixed up.  :-)

Either way, the LCL still has the Color property as 'public' instead
of 'protected'.


An advantage of having it public, is that you can pass a TControl to the 
widget interface and it can access the Color property without resorting 
to cast to decendants. I don't know if this technique is actually used 
though.


There are several properties where this feature would be welcome, eg 
tcustomedit.text, tcustomcheckbox.checked, but you can use the following 
workaround when necessary:


type
  tcustomeditfriend = class(tcustomedit);

...

tcustomeditfriend(edit).edit := 'value';

--
Joao Morais

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-07 Thread Vincent Snijders

Graeme Geldenhuys schreef:

On 5/6/07, Michael Van Canneyt <[EMAIL PROTECTED]> wrote:


TControl non visual ?? How is that ? TLabel or TImage are very visual...
Non-windowed, you mean ?


Ah ok, I got it mixed up.  :-)

Either way, the LCL still has the Color property as 'public' instead
of 'protected'.


An advantage of having it public, is that you can pass a TControl to the widget 
interface and it can access the Color property without resorting to cast to 
decendants. I don't know if this technique is actually used though.


Vincent

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-06 Thread Graeme Geldenhuys

On 5/6/07, Michael Van Canneyt <[EMAIL PROTECTED]> wrote:


TControl non visual ?? How is that ? TLabel or TImage are very visual...
Non-windowed, you mean ?


Ah ok, I got it mixed up.  :-)

Either way, the LCL still has the Color property as 'public' instead
of 'protected'.


--
Graeme Geldenhuys

There's no place like S34° 03.168'  E018° 49.342'

_
To unsubscribe: mail [EMAIL PROTECTED] with
   "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives


Re: [lazarus] TControl and public Color property???

2007-05-06 Thread Michael Van Canneyt


On Sun, 6 May 2007, Graeme Geldenhuys wrote:

> Hi,
> 
> Could somebody explain this one to me, or is it just an oversight?
> Why does the TControl class have a public Color property?  This is not
> Delphi and Kylix compatible.  Under Delphi/Kylix it is a protected
> property.
> 
> This brings me to another question. Why does the TControl class have a
> Color property in the first place. TControl is supposed to be
> non-visual!  Shouldn't Color only be introduced in TWinControl?

TControl non visual ?? How is that ? TLabel or TImage are very visual...
Non-windowed, you mean ? 

Michael.

_
 To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives