Subject Re: [IBO] Set the readonly-flag to prevent from editing some fields in a IB_Grid
Author Helen Borrie
At 01:07 AM 9/02/2007, you wrote:
>Hi,
>
>i would like to set readonly in a ib_grid for some fields like this:
>
> for i := 0 to qryLagerBew.FieldCount - 1 do
> begin
> if ( ( qryLagerBew.Fields[i].FieldName <> 'LB_BUCHUNGSTEXT' )AND
> ( qryLagerBew.Fields[i].FieldName <> 'LB_VERP_MENGE' )AND
> ( qryLagerBew.Fields[i].FieldName <> 'LB_TEXT_INTERN' ) )
> then qryLagerBew.Fields[i].ReadOnly := true;
> end; // for i
>
>this way isn't accept by Delphi5. how to do it?

Have you tried setting the FieldsReadOnly structure of the dataset?

with qryLagerBew do
begin
FieldsReadOnly.Clear;
for i := 0 to qryLagerBew.FieldCount - 1 do
begin
if ( ( qryLagerBew.Fields[i].FieldName <> 'LB_BUCHUNGSTEXT' )AND
( qryLagerBew.Fields[i].FieldName <> 'LB_VERP_MENGE' )AND
( qryLagerBew.Fields[i].FieldName <> 'LB_TEXT_INTERN' ) )
then FieldsReadOnly.Add(Fields[i].FieldName + '=T');
end; // for i

Note, you can also qualify the modes where you want the attribute to
apply, i.e.

acolumnname=T;NOEDIT;NOINSERT;NOSEARCH
bcolumnname=F;NOEDIT;NOINSERT

etc.

I have an idea that the ReadOnly property of a field is itself a
read-only property, considering that e.g. expression fields and
calculated fields are read-only by nature. Setting the
FieldsReadOnly property to F[alse] on such fields would cause an
exception at some point.

The dataset would need to be inactive and unprepared at the time
these changes were done.

What was the actual exception you saw?

Helen