Discussion:
ClientDataSet and "Field Value Required" - But None of the Fields are Required
(too old to reply)
Rascal
2008-04-04 12:03:30 UTC
Permalink
Hi,

I have a strange problem here:

Delphi 2007

1. ClientDataSet grabs its dataset from a stored procedure (SP executes a
SELECT statement to return a cursor).
2. All the persistent fields (added to Fields Editor @ design-time) have
their Required property set to False.
3. Two more fields found in the FieldDefs have faRequired in their
Attributes property - those two are not created @ design-time (and do not
appear in the Fields Ediotor)

Upon "Post" I receive "Field Value Required". Unfortunately, the exception
does not say WHAT field is required.
(http://qc.codegear.com/wc/qcmain.aspx?d=54380)

What I have found out is that I have to

0. Set DisableStringTrim to true for CDS
1. Add to the set of persistent fields ALL the fields from the SP's dataset
2. Loop through FieldDefs
3. Set a dummy value (i.e. ' ' for ftString) for those fields that have
faRequired in Attributes (+ VarIsNull(field.value) = true for those fields).

Then I can post.

Now the problem is that I'm trying to convert a Delphi 3 application to
D2007. I have loads of CDS's and SP's ... and the code in D3 never reported
"Field Value Required"

Questions:

1. Why Delphi says "Field Value Required" when Required for Field is set to
False (manually).

2. Is there a workaround?

3. Is there a way to know exactly what field IS required in the Exception
raised?

-rascal
vavan
2008-04-07 07:33:16 UTC
Permalink
Post by Rascal
1. Why Delphi says "Field Value Required" when Required for Field is set to
False (manually).
see "Better exception for required fields" thread in .multi-tier for
explanation. when you open cds midas transfers field attributes from
provider side so it doesn't matter what attributes cds field has
Post by Rascal
2. Is there a workaround?
you could create persistent fields on provider side and set required
attribute there. or do it in the code
Post by Rascal
3. Is there a way to know exactly what field IS required in the Exception
raised?
not with native borland implementation, no
--
Vladimir Ulchenko aka vavan
Rascal
2008-04-07 12:08:13 UTC
Permalink
Vladimir,
Post by vavan
Post by Rascal
2. Is there a workaround?
you could create persistent fields on provider side and set required
attribute there. or do it in the code
Do what from code!?

I have persistent fields created for the ClientDataSet. All are manually set
to Required = False.

Before I post I check if Required is false, and it is not. But OnPostError
is raised with "Field Value Required"

This is either a bug or I'm missing some functionality of TClientDataSet /
TDataSetProvider.

Is there a property to set and say "do not look inside the DB table to
presume what fields are required."


-rascal
vavan
2008-04-08 06:57:46 UTC
Permalink
Post by Rascal
Do what from code!?
I think you could hook OnAfterOpen event on provider side of your
dataset and set properties there
Post by Rascal
This is either a bug or I'm missing some functionality of TClientDataSet /
TDataSetProvider.
no this isn't bug (well at least it works as designed) and yes you're
missing the point of my previous post. it doesn't matter what field
attributes you set on cds side. you have to set those on provider
side. you should create persistent fields for dataset assigned to
provider and set field properties there
Post by Rascal
Is there a property to set and say "do not look inside the DB table to
presume what fields are required."
there's no such property but as I explained those field attributes
won't be overriden if you create persistent fields and set them
manually
--
Vladimir Ulchenko aka vavan
Loading...