[fpc-devel] Should TAutoIncField be read only?
Luiz Americo Pereira Camara
luizmed at oi.com.br
Thu May 20 12:01:34 CEST 2010
Joost van der Sluis escreveu:
> On Wed, 2010-05-19 at 14:14 -0300, Luiz Americo Pereira Camara wrote:
>> I'm just confused by the exception that is raised ("autoinc fields are
>> read only") when trying to set a value and by the code in the
>> TAutoIncField constructor that initializes FReadOnly to true.
>> Attached is a patch that removes this initialization.
> That's indeed strange. And it would mean that those fields are
> effectively readonly. I think they shoudn't be. (But to be sure, if it
> would have been my design, there woudn't be such a thing as an autoinc
> I see two choices: make it possible to edit autoinc fields, or make
> ReadOnly true.
> Maybe we should choose the second option, for Delphi-compatibility?
The funny thing is that, currently, fpc has the same behavior as Delphi,
i.e., the field is effectively read only (fpc and Delphi raise the same
exception when trying to set the value) but the ReadOnly property is
false. Also, in both CanModify is true.
IMO this is a Delphi bug (Can someone test on > Delphi 7?). A quote from
property ReadOnly: Boolean;
Set ReadOnly to true to prevent a field from being modified. In a data
grid, tabbing from field to field skips over ReadOnly fields.
To learn whether a field can be modified, use the CanModify property
instead. CanModify reflects not only the value of the ReadOnly property,
but also any restrictions imposed by the underlying dataset.
Note: Auto-incrementing fields are a function of the database
back-end. An application should not attempt to set a field value for an
autoincrement field (with or without a TAutoIncField object).
More information about the fpc-devel