 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ignacio Vazquez Guest
|
Posted: Tue Aug 05, 2003 2:45 pm Post subject: Re: inherited |
|
|
"Alessandro" <alessandro (AT) tergus (DOT) com.br> wrote in message
3f2fc287$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Hi. I have a form1 that descend of other form (Form1). In form1 exist a
private variable. When i inherited this form i cant use this variables.
How can i do this ?
|
Change the visibility of the field in the base class to protected.
Cheers,
Ignacio
--
No, don't send me e-mail directly. No, just don't.
|
|
| Back to top |
|
 |
Alexander Bauer Guest
|
Posted: Wed Aug 06, 2003 11:21 am Post subject: Re: inherited |
|
|
Hi,
If you put you variable to Private you can only access it from other classes
in the came unit.
If you put you variable to Protected you can access it from other classes in
the same unit and in descendants of the class (also in other units).
If you put you variable to Public you can access it allways, but it's not
shown in the propertylist in the object-inspector.
If you put you variable to Published you can access it alway and it's shown
in the object-instpector.
So if you want to use you variable in a descendant but don't want it to be
accessable form anywhere else you may best put it in the Protected section.
Because I did so often needed to access functions, procedures, properties,
variables and stuff from the VCL-Control I derived my controls form and I
could not because they where declared private or the procedure / function
was static, I use only protected, public and sometimes published in my
abstract classes (eg. TawCutomListView) and all my procedures and functions
(even property read and write proc's / func's) are virtual. So I can access
all variables and override all proc's and func's in a derived class of my
classes.
Regards,
Alexander Bauer
"Alessandro" <alessandro (AT) tergus (DOT) com.br> schrieb im Newsbeitrag
news:3f2fc287$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Hi. I have a form1 that descend of other form (Form1). In form1 exist a
private variable. When i inherited this form i cant use this variables.
How
can i do this ?
Thanks
|
|
|
| Back to top |
|
 |
Alexander Bauer Guest
|
Posted: Fri Aug 08, 2003 12:57 pm Post subject: Re: inherited |
|
|
OK, but if you implement a private function new the new version will only be
called in your new class, so you have to override / reimplement all
functions and stuff where that private reimplementated function is called in
the class you derived your new one from. And, it has no effect to other
classes, if I override a function in a descendant of a class. So, if you eg
have your property set functions protected you can override it and no matter
where in the descendant class the property meight be set or the setfunction
is called, you can be sure that your new one is called. But if you declared
it private you will have to override any function of the descendant class
where the property is set or / and the setfunction is called and you'll also
have to redefine the property it self because in the descendant allways the
"old" version will be used, so your new behavior of the property will not
properly take effect.
I like it more to have full access to all variables procedures and functions
of the original class in my new version than to write the half class again
just because all is declared private. I don't see any dependency trouble or
side kicks of any implementation since I declaread anything protected
anymore. But may be I simply don't understood your point.
Regards,
Alexander Bauer
"Richard Atkinson" <rpIHateSpamAtkinson (AT) bigpond (DOT) com> schrieb im Newsbeitrag
news:3f32eb9e (AT) newsgroups (DOT) borland.com...
| Quote: |
Because I did so often needed to access functions, procedures,
properties,
variables and stuff from the VCL-Control I derived my controls form and
I
could not because they where declared private or the procedure /
function
was static, I use only protected, public and sometimes published in my
abstract classes (eg. TawCutomListView) and all my procedures and
functions
(even property read and write proc's / func's) are virtual. So I can
access
all variables and override all proc's and func's in a derived class of
my
classes.
Whereas I make methods private if at all possible. That way I reduce
dependency between classes and can be sure if I change the implementation
of
a private method that it will not effect any other classes. I see this as
one of the powerful features of OO programming - encapsulation.
But, whatever works for you.
FWIW
Richard Atkinson
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|