Subject RE: [IBO] Preventing a field from being updated
Author Claudio Valderrama C.
I think OnValidateRecord's task is to prevent the post to happen, but not
to revert to the previous value. This is my understanding. When it was
introduced or when I began using it, I had problems with this event so I
stopped coding it, but this was more than a year ago.
When you reject a value, the dataset remains in its previous state, be it
insert or delete. Perhaps if you explain better what you want, a better idea
may be given:
- Can't you play with the R/O flag of the field you don't want to be changed
by the user? Also, you can alter directly the ReadOnly and Visible
properties of the associated control. You can associate methods to the
OnBeforeModify and OnAfterModify events of TIB_Column in the dataset's
AfterPrepare event, when the fields have been created.
- You can set Prevent* properties at the column level, too, not only at the
dataset level.
- Do you want to stop the post if a value is changed or do you want to undo
the change silently? The latter can be done in the BeforePost event.
Let me say your approach is counter-practice in my opinion. When a value is
rejected, usually it remains with the wrong value. There's a method,
TIB_Column.FocusControl, that you can invoke to try to give focus to the
control bound to the field. But it's up to the user to correct the mistake,
by pressing ESC to restore the control's old value. But if you still want to
make things in the unusual way, here's code:

procedure TForm1.IB_Query1ValidateField(Sender: TIB_Statement;
ARow: TIB_Row; AField: TIB_Column);
begin
if ((Sender as TIB_Dataset).State = dssEdit)
and (AField.FieldName = 'A') and (AField.Value <> AField.OldAsVariant)
then begin
AField.FocusControl;
ActiveControl.Perform(EM_UNDO, 0, 0);
if ActiveControl is TIB_Edit
then TIB_Edit(ActiveControl).SelectAll
else if (ActiveControl is TIB_Grid)
then With TIB_Grid(ActiveControl) do
if EditorMode
then EditorMode := False;
Abort
end
end;

By using this code, you agree that I cannot accept any liability if your
application becomes broken. :-)

C.

> -----Original Message-----
> From: Marc Leclerc [mailto:mlpgr@...]
> Sent: Viernes 16 de Marzo de 2001 12:08
>
> Has anyone got this to work before ?
>
> Thanks
>
> ----- Original Message -----
> From: "Marc Leclerc" <mlpgr@...>
> To: <IBObjects@yahoogroups.com>
> Sent: Thursday, March 15, 2001 5:13 PM
> Subject: Re: [IBO] Preventing a field from being updated
>
>
> > Hi,
> >
> > This is not the final code but just something put together for
> simplicity.
> I
> > have more to do in there including the option to delete the details and
> > allow the change.
> >
> > > Marc,
> > >
> > > I don't see that you raised an exception in your code
> (Showing a message
> > > isn't raising an exception). Have you tried to do so?
> > >
> >
> > <Delphi snip>
> > Abort raises a special "silent exception" (EAbort), which operates like
> any
> > other exception, but does not display an error message to the end user
> > <>
> > > And don't use RecordCount; there are better ways to check if records
> > > exists.
> > >
> > > You can use:
> > >
> > > if ( NOT IB_QueryContributions.IsEmpty )
> > > or:
> > > if ( NOT IB_QueryContributions.FieldbyName('PrimaryKeyField').IsNull )
> > >
> > ... not IB_QueryContributions.Eof also
> > > instead.
> > >
> > > Luc.
> > >
> > >
> > >
> > >
> > > Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
> > >
> > >
> >
> >
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
> >
> >
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>