DelphiFAQ Home Search:

Hide properties without using TCustomXXX classes


commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Sometimes you will want to hide some properties from access by the object inspector. Unfortunately, VCL does not always offer you TCustomXXX classes where all properties are protected.
The following trick shows, how to do it..
This piece of code hides the properties VertScrollbar and HorzScrollbar in the object inspector and shows how to access the hidden properties in your source code (see method Switch).

unit HideProp;


  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs;

  THideProp = class(TScrollBox)
    Foo: Boolean;
    { the properties which are to hide are redefined as
	  read-only dummy properties.
      That way they will not appear in object inspector. }
    property VertScrollBar: Boolean read Foo;
    property HorzScrollBar: Boolean read Foo;
    procedure Switch;   { activate/deactivate scrollbars }

procedure Register;


procedure Register;
  RegisterComponents('Sample', [THideProp]);

{ Toggle for Scrollbars. Just a sample to show,
  how you still can access the original properties.. }
procedure THideProp.Switch;
  inherited VertScrollBar.Visible := Not inherited VertScrollBar.Visible;
  inherited HorzScrollBar.Visible := Not inherited HorzScrollBar.Visible;



2008-05-15, 14:47:20
anonymous from United States  
What do you begin the code with? is it like:

2014-07-17, 05:43:49
anonymous from Spain  
If you want some properties to be shown, but not saved...

Add Stored False to property definition, just like:

property MyProp:Integer read R_BlaBlaBla write W_BlaBlaBla Stored False;

It works for allmost any property (with that they are not saved inside the .dfm).

Warning: Values will get lost if not procesed

Possible use: Have some properties to be shown that will allways have a 'custom' value.

Best use for: Localization get reduced a lot on some situations whrere such values for such properties are not needed.

P.D.: If you want to force a property to be saved... use Stored True;
P.P.D.: If you want to force a property to be saved or not... use Stored {Some conditional};



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: