Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread Puzzling BeforePost problem
Fri, Feb 3 2006 2:14 PMPermanent Link

Kai Peters

Hi ~

In the example below, the field 'Appointment_Film' is set as 'Required' in
table 'TodaysAppointments'.

If I try and post a new record, DBIsam - much to my suprise - complains=
that
"Field 'Appointment_Film' must have a value"??? on the first line of the=
proc
below.

I cannot run GetNextFilmNumber any earlier as it sets a shared counter on=
the
network and if a user canceled, the film number would be "wasted" and I=
don't
allow 'holes' in the numbering.

I am supplying a number BEFORE the post so why would it behave like this?

TIA,
Kai


//--------------------------------------------------------------------------=
----
procedure TDM_DBIsam.dbisamtable_TodaysAppointmentsBeforePost(DataSet:
TDataSet);
begin
 // we always need one of these if not yet there
 if ( Dataset.FieldByName( 'Appointment_Film' ).Value =3D NULL ) then
 begin
   NewFilmNumber :=3D GetNextFilmNumber;
   if ( NewFilmNumber =3D '' ) then
   begin
     MessageDialog( 'Could not obtain new film number - cannot save this
appointment!', mtError );
     DataSet.Cancel;
     Exit;
   end
   else
     Dataset.FieldByName( 'Appointment_Film' ).AsString :=3D NewFilmNumber;
 end;
Fri, Feb 3 2006 3:08 PMPermanent Link

Sean McCall
Kai,

Try

if Dataset.FieldByName( 'Appointment_Film' ).IsNull then...

The field requirements are validated after
TDataset.Beforepost method of TDataset, so my guess is that
your code isn't executing as expected. Its possible that an
empty string field will return a variant (TField.Value) of a
string with a length of zero rather than a NULL variant.

Have you stepped through the code & evaluated what is going on?

Sean


>  Kai Peters wrote:
> Hi ~
>
> In the example below, the field 'Appointment_Film' is set as 'Required' in
> table 'TodaysAppointments'.
>
> If I try and post a new record, DBIsam - much to my suprise - complains that
> "Field 'Appointment_Film' must have a value"??? on the first line of the proc
> below.
>
> I cannot run GetNextFilmNumber any earlier as it sets a shared counter on the
> network and if a user canceled, the film number would be "wasted" and I don't
> allow 'holes' in the numbering.
>
> I am supplying a number BEFORE the post so why would it behave like this?
>
> TIA,
> Kai
>
>
> //------------------------------------------------------------------------------
> procedure TDM_DBIsam.dbisamtable_TodaysAppointmentsBeforePost(DataSet:
> TDataSet);
> begin
>   // we always need one of these if not yet there
>   if ( Dataset.FieldByName( 'Appointment_Film' ).Value = NULL ) then
>    begin
>     NewFilmNumber := GetNextFilmNumber;
>     if ( NewFilmNumber = '' ) then
>     begin
>       MessageDialog( 'Could not obtain new film number - cannot save this
> appointment!', mtError );
>       DataSet.Cancel;
>       Exit;
>     end
>     else
>       Dataset.FieldByName( 'Appointment_Film' ).AsString := NewFilmNumber;
>   end;
>
Fri, Feb 3 2006 5:19 PMPermanent Link

Kai Peters
On Fri, 3 Feb 2006 12:08:26 -0800, Sean McCall wrote:
> Kai,
>
> Try
>
> if Dataset.FieldByName( 'Appointment_Film' ).IsNull then...
>
> The field requirements are validated after
> TDataset.Beforepost method of TDataset, so my guess is that
> your code isn't executing as expected. Its possible that an
> empty string field will return a variant (TField.Value) of a
> string with a length of zero rather than a NULL variant.
>
> Have you stepped through the code & evaluated what is going on?
>
> Sean

Sean ~

IsNull also does not work and I do not have access to the source code.

I don't believe my code to be faulty - the moment I hit the post button on
the dbnavigator I am in the BeforePost event and it complains on the first=
line
of that as described....

(I am running 4.05 I believe)

Kai

Fri, Feb 3 2006 5:43 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Kai,

<< In the example below, the field 'Appointment_Film' is set as 'Required'
in table 'TodaysAppointments'.

If I try and post a new record, DBIsam - much to my suprise - complains that
"Field 'Appointment_Film' must have a value"??? on the first line of the
proc below. >>

Set the Required property of the TField for the Appointment_Film field to
False like this:

Dataset.FieldByName( 'Appointment_Film' ).Required:=False;

after the table is opened.  That will stop the db.pas unit from displaying
that error message before the BeforePost event is executed.

--
Tim Young
Elevate Software
www.elevatesoft.com

Fri, Feb 3 2006 6:11 PMPermanent Link

Kai Peters

> Set the Required property of the TField for the Appointment_Film
> field to False like this:
>
> Dataset.FieldByName( 'Appointment_Film' ).Required:=3DFalse;
>
> after the table is opened.  That will stop the db.pas unit from
> displaying that error message before the BeforePost event is
> executed.

Thanks Tim ~

that is what I had done already to circumvent the problem.

I'd still reason that my code should have worked - after all, I supplied
data for a a required field in a BEFOREPost event which should run BEFORE
attempting to post as the name suggests...

Would you care to elaborate/educate why there is a need to work around it?

TIA,

Kai
Fri, Feb 3 2006 6:25 PMPermanent Link

Kai Peters

>
> Thanks Tim ~
>
> that is what I had done already to circumvent the problem.
>
> I'd still reason that my code should have worked - after all, I
> supplied data for a a required field in a BEFOREPost event which
> should run BEFORE attempting to post as the name suggests...
>
> Would you care to elaborate/educate why there is a need to work
> around it?
>
> TIA,
>
> Kai

Tim ~

and one more round:

I have actually two fields that are being set in the BeforePost event=
(second
field & assoc. code was omitted for clarity) and the second field did not=
cause
the afore mentioned problems at all (even though it was still required)

That of course confused me even more - until I realized that the field=
causing
the problem is used in an index and the second one is not.

So it seems that your/Borland's code may try to "post to the index" first=
before
generating the OnBeforePost (for the data) event?

If so, is that not the wrong order of things?

TIA,
Kai
Sat, Feb 4 2006 6:43 AMPermanent Link

"Tony Pomfrett"
Kai,

From the Delphi 5 Help file:

"BeforePost is triggered when an application calls the Post method.
Post checks to make sure all required fields are present, then calls
BeforePost before posting the record."

So the checking of required fields is done before the BeforePost method is
called.

Tony.

"Kai Peters" <kpeters@mvinc.net> wrote in message
news:20062315250.882900@KAI...

>
> Thanks Tim ~
>
> that is what I had done already to circumvent the problem.
>
> I'd still reason that my code should have worked - after all, I
> supplied data for a a required field in a BEFOREPost event which
> should run BEFORE attempting to post as the name suggests...
>
> Would you care to elaborate/educate why there is a need to work
> around it?
>
> TIA,
>
> Kai


Mon, Feb 6 2006 11:47 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Kai,

<< I'd still reason that my code should have worked - after all, I supplied
data for a a required field in a BEFOREPost event which should run BEFORE
attempting to post as the name suggests... >>

This is a Borland thing - they designed TDataSet to call BeforePost *after*
checking the Required property of the TFields.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image