Pregunta

My problem is next:

I have my own DBGrid, based on TDBGrid.

Because in many places better to see the Selection, I thought I set it on Create, and the property editor save the Options property if I set it as False later. So constructor create it as:

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

Ok, I thought that is ok, because I set it as True, the creation is making it True at first, but on the Loaded the Delphi will changed it to the good value (False).

But the experience shown that this don't working now!

I don't know why.

I put my own dbgrid on a Form1. The ASS option is on. I set it to false.

I start the application. And NOW this is ON AGAIN. When I show the value of Option on LOaded, I got True value. So the value is don't loaded as needed.

I don't know why it is happened, but I think this is based on "Default"??? May default is False, so if I set it to False, then it is don't save the values into the DFM...

So what is the possible way to I save the values without this effect?

Thanks for your help: dd

¿Fue útil?

Solución

The Delphi streaming system only stores properties when they differ from their default values. These default values can be implicit (like 0 for Integer and '' for strings) and they can be set explicitely by the default keyword. This is the case for TDbGrid.Options, too ([dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit, dgTitleClick, dgTitleHotTrack]).

As long as you don't change any other option in the set, by setting dgAlwaysShowSelection to false you end up with the default value and that isn't stored in the DFM. Now as you set dgAlwaysShowSelection to true inside Create and nothing is stored in the DFM, the option will be on after loading, even if it had been off when stored.

To accomplish your needs, you not only have to set the option to true in the constructor, but also specify the changed default value to make the streaming system aware of this change.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top