Delphi: DBGrid options not saved?

My problem is this:

I have my own TDBGrid based DBGrid.

Since it’s better to see Selection in many places, I thought I set it to Create, and the property editor would save the Options property if I later set it to False. Therefore, the constructor creates it as:

constructor TMyDBGrid.Create(aOwner: TComponent); begin inherited Create(aOwner); Options := Options + [dgAlwaysShowSelection]; end; 

Well, I thought that everything was fine, because I set it to True, the creation first makes it True, but on Loaded Delphi it will change it to a good value (False).

But experience has shown that this does not work now!

I do not know why.

I put my own dbgrid in Form1. The ASS option is enabled. I set it to false.

I am running the application. AND NOW, IT'S AGAIN. When I show the Option value on LOaded, I got the value True. Therefore, the value is not loaded as needed.

I do not know why this happened, but I think it is based on "Default" ??? The default value is False, so if I set it to False, then it does not save the values ​​in DFM ...

So what is the possible way to store values ​​without this effect?

Thanks for your help: dd

+4
source share
1 answer

The Delphi streaming system only saves properties when they differ from the default values. These default values ​​can be implicit (for example, for integers and strings), and they can be specified using the default keyword. This also applies to TDbGrid.Options ([dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit, dgTitleClick, dgTitleHotTotleHotTotleHotTotleHot).

Until you change any other parameter in the set by setting dgAlwaysShowSelection to false, you will get a default value and not stored in DFM. Now, when you set dgAlwaysShowSelection to true inside Create and nothing is stored in DFM, the option will be enabled after loading, even if it was disabled during saving.

To fulfill your needs, you need to not only set the value to true in the constructor, but also specify the changed default value so that the streaming system knows about this change.

+5
source

All Articles