AFAIK, it is not possible to directly reduce visibility of a property from a
base class. It would be good if a new keyword such as "hide" could be
introduced. for example;
TNewClass = class(TBaseClass)
private
...
protected
...
hide
property Color;
porperty Len;
...
published
property Width;
...
end;
Reasons this is not (and should not be) done:
1) On principle, public/published properties and methods of a class should
be considered a contract. Once given, it cannot be taken away. Those knowing
the ancestry of a class would rightly expect to be able to access
public/published inherited items.
2) In practice, allowing this would actually break code. Specifically it
would cause errors where the base class was being used polymorphically.
Consider the following example:
type
TBase = class
public
property Visible: boolean;
end;
TFoo = class(TBase)
end;
TBar = class(TBase)
end;
THide = class(TBase)
hide
property Visible;
end;
// fill a list with a number of TBase descendants
var base: TBase;
begin
for base in list do
base.Visible := True;
If the list contains any THide instances, the above blows up, but it should
not since it is *properly* depending on polymorphism.
--
Wayne Niddery - TeamB (www.teamb.com)
Winwright, Inc. (www.winwright.ca)
All code based on getting the class in runtime, for instance with
GetClass('TMyBusinessClass') would potentially fail as well.
Regards
Actually I want to hide them only from the Object Inspector. i.e. I want to
hide published properties. It can still remain as public so its scope level
won't change.
My problem is that there are lots of published properties in ancestor that
makes a newly derived Component very hard to browse in Object Inspector.
"Wayne Niddery (TeamB)"
> Actually I want to hide them only from the Object Inspector. i.e. I want to
> hide published properties. It can still remain as public so its scope level
> won't change.
>
> My problem is that there are lots of published properties in ancestor that
> makes a newly derived Component very hard to browse in Object Inspector.
Hello Farshad
This could be solved with a 'Proxy' or 'Facade' style component, which
contains an embedded (private) instance of the real component and
publishes only the required properties and methods.
With SetSubcomponent(True) the embedded component could be shown as a
'nested' component in the inspector for optional fine-tuning.
Hope this helps (tm)
Michael Justin
--
betasoft - Software for Delphi™ and for the Java™ platform
http://www.mikejustin.com/
http://www.betabeans.de/
Hello,
Thanks. I know but using above method will change base class of your
component. For example if it is a TDataSet descendant you won't be able to
plug it into a datasource.
Ok. Depends on the component you are descending from, but many of the VCL
controls have a "Custom" ancestor where the properties are just public, e.g.
you'll see that TEdit descends from TCustomEdit and the only thing TEdit
really does is promote public properties to published. In this case descend
from TCustomEdit and publish just those properties you want.
I see. My Component is a descendant of TDataSet so really no way to go back
and use a Custom version. Really isn't there any way to hide a published
property? IIRC, I saw a 3rd party component, a descendant of TQuery with
less properties than the original TQuery. I need to remember its name and
examine its code.
You should've taken a look - in the case of TDataset, it has no published
properties except any inherited from TComponent. Only descendants publish
TDataset properties.
DesignIntf.UnlistPublishedProperty in the latest Delphi versions.
Vlad
Thank you very much for the info. That's the only way to hide a property.
Here is the comment from Borland in file DesignIntf.pas:
{ UnlistPublishedProperty
From time to time there is a need to hide a property that has been
published by
an ancestor class. Whenever this occurs you should make sure that you are
descending from the right class. We realize, though, that sometimes this
is not
feasible. The following procedure will therefore allow you to make a
specific
property on a specific class not appear in the Object inspector.
** Please note that this function does not stop the streaming system from
streaming the published property nor does it make the published property
from
begin programmatically access at runtime. It simply tells the object
inspector
not to list (and in turn edit) it when components of the specified class
are
selected. }
"Vladislav Filyakov" <vl...@devexpress.com> wrote in message
news:47e91a6c$1...@newsgroups.borland.com...
> ** Please note that this function does not stop the streaming system from
> streaming the published property nor does it make the published property
> from
> begin programmatically access at runtime. It simply tells the object
> inspector
> not to list (and in turn edit) it when components of the specified class
> are
> selected. }
Note this well !!!
This technique does *not* hide a property, it only prevents a property
declared on a component from being seen in the object inspector at
design time.
I would reiterate that the requirement to hide public/published
properties in derived classes is symptomatic of very poor class design.
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
Any data aware component will accept TDataSource descendants for their
DataSource property, so you could solve that problem by adding a
published MyDataSet: TMyDataSetWrapper property to a TMyDataSource =
class(TDataSource). The setter of that property would simply assign the
wrapped dataset to the DataSet property of the datasource.
FWIW and to the extent it at all makes sense to discuss unimplemented
and not fully specified semantics; I don't think so. The Visible
property is only hidden in THide. If you cast the instance to TBase (and
the above code does that), the Visible property would have the
visibility it has in TBase.