Mega Code Archive

 
Categories / Delphi / Examples
 

Hide properties without using tcustomxxx classes

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; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs; type THideProp = class(TScrollBox) private Foo: Boolean; protected public published { 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 } end; procedure Register; implementation procedure Register; begin RegisterComponents('Sample', [THideProp]); end; { Toggle for Scrollbars. Just a sample to show, how you still can access the original properties.. } procedure THideProp.Switch; begin inherited VertScrollBar.Visible := Not inherited VertScrollBar.Visible; inherited HorzScrollBar.Visible := Not inherited HorzScrollBar.Visible; end; end.