Board index » delphi » Hiding properties from derived class - how?

Hiding properties from derived class - how?

Hi,

I'm trying to write my own component, and I wonder if it's possible to hide
some proporties from the derived class (in design time). For example , I
made a class derived from TCustomControl and want to hide the property
'align' to the end-user, who uses my component.

Any info is welcome !
thanx
Jan

 

Re:Hiding properties from derived class - how?


Quote
Jan wrote in message <6vv2kh$62...@news2.xs4all.nl>...
>I'm trying to write my own component, and I wonder if it's possible to hide
>some proporties from the derived class (in design time). For example , I
>made a class derived from TCustomControl and want to hide the property
>'align' to the end-user, who uses my component.

Well, TCustomControl doesn't publish any properties at all, so you'd
only get "standard" properties from TControl and TWinControl (Left,
Top, HelpContext etc). There's not much point hiding these.

For a more real situation, let's say you want a TLabel without an
Align property, just derive your new class from TCustomLabel.
You can now publish as many properties as you want. A hint -
after you've derived your class, copy and paste the "published"
section from TLabel, and simply delete any properties you
don't want. Anything you delete won't appear in the Object Inspector.

HTH
--
Jeremy Collins
Kansai Business Systems

Re:Hiding properties from derived class - how?


Quote
>Well, TCustomControl doesn't publish any properties at all, so you'd
>only get "standard" properties from TControl and TWinControl (Left,
>Top, HelpContext etc). There's not much point hiding these.

Is it not possible at all ?  I want to replace Left, Top , Width and Height
with other properties like Xsource,Ysource, Xdest and Ydest.

thnx
Jan

Re:Hiding properties from derived class - how?


Quote
Jan wrote in message <7006t5$3d...@news2.xs4all.nl>...
>>Well, TCustomControl doesn't publish any properties at all, so you'd
>>only get "standard" properties from TControl and TWinControl (Left,
>>Top, HelpContext etc). There's not much point hiding these.

>Is it not possible at all ?  I want to replace Left, Top , Width and Height
>with other properties like Xsource,Ysource, Xdest and Ydest.

Yes, it's possible. Following from my previous post, add the
properties you want to hide to the Published section, but
make them read-only:

Example:

  TMyLabel = class(TCustomLabel)
  private
    FLeft : integer;
   :
  published
    :
    property Left : integer read FLeft;
   :
  end;

Note that the new "Left" doesn't have any functionality,
and also there is no "write" clause. There will be no
"Left" in the Object Inspector, and trying to assign a
value to "Left" in code will cause a compile-time error.

HTH
--
Jeremy Collins
Kansai Business Systems

Other Threads