What's the simplest way to override a property's default value?

I'm trying to write a TCustomDBGrid descendant that's designed to feel like a TListBox.  One of the things I want to change is the Options property's defaults.  TCustomDBGrid defines Options as:

    property Options: TDBGridOptions read FOptions write SetOptions
      default [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit];

Trying to override that in my class with

      property Options: TDBGridOptions default
         [dgTitles, dgTabs, dgRowSelect, dgAlwaysShowSelection, dgCancelOnExit];

doesn't work; the compiler expects *read* or *write* after the type, not *default*.  Problem is, FOptions and SetOptions are both defined as private, not protected, in TCustomDBGrid.

Do I have to write my own get and set methods that invoke "*inherited* Options", or is there a simpler way?
0
Mason
12/3/2008 8:55:47 PM
embarcadero.delphi.oodesign 456 articles. 0 followers. Follow

1 Replies
849 Views

Similar Articles

[PageSpeed] 25

Mason Wheeler wrote:
> I'm trying to write a TCustomDBGrid descendant that's designed to feel like a TListBox.  One of the things I want to change is the Options property's defaults.  TCustomDBGrid defines Options as:
> 
>     property Options: TDBGridOptions read FOptions write SetOptions
>       default [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit];
> 
> Trying to override that in my class with
> 
>       property Options: TDBGridOptions default
>          [dgTitles, dgTabs, dgRowSelect, dgAlwaysShowSelection, dgCancelOnExit];

That merely changes the value that the IDE treats as the one it doesn't 
need to bother storing to the DFM when it saves the form and its 
components. It has absolutely no effect at run time, and it does not 
change the value of any property.

> doesn't work; the compiler expects *read* or *write* after the type, not *default*.

Try removing the type.

property Options default ...;

> Problem is, FOptions and SetOptions are both defined as private, not protected, in TCustomDBGrid.
> 
> Do I have to write my own get and set methods that invoke "*inherited* Options", or is there a simpler way?

Since you haven't actually changed what the initial value will be for 
that property, you'll still need to write some code. Do it in the 
constructor:

begin
   inherited;
   Options := NewDefaultOptions;
end;

Any forms that were using the old set of default options will get the 
new set the next time the form is loaded (at design time or run time). 
This is because the Options property was never saved for that form 
anyway, due to the "default" directive on the original property declaration.

-- 
Rob
0
Rob
12/3/2008 9:10:44 PM
Reply: