MemDataSet "field not found" on setting calculated field val
Posted: Fri 14 May 2010 10:11
Hi,
For some reason, TMemDataSet raises "Field not found" when setting a value on a calculated field.
I tried reproducing this in a test application, but there it works fine.
The Delphi "Field not found" error has quotes around the field name and I noticed TMemDataSet has not.
I do not have the source of TMemDataSet, so I cannot trace into it
This error has been annoying me for hours.
Here's the call stack:
All fields are set to ReadOnly = False.
The code in OnCalcField is very simple:
and the name of the field in the error message is the name of DataSet.Fields[n]
Any clue what could cause this?
Edit:
The calculated field is added before I do .Open -- when I call .Prepare before the call to FieldDefs.Update and adding the fields, the test application fails with the error message "Field not found." when this is not done, it works fine.
So, currently, this is what's done:
1) query with SQL statement
2) .Prepare
3) .FieldDefs.Update;
4) add calculated field
5) .Open
6) In OnCalcFields event: MyCalcField.AsBoolean := False;
Step 6 fails if step 2 is included, why?
For some reason, TMemDataSet raises "Field not found" when setting a value on a calculated field.
I tried reproducing this in a test application, but there it works fine.
The Delphi "Field not found" error has quotes around the field name and I noticed TMemDataSet has not.
I do not have the source of TMemDataSet, so I cannot trace into it

This error has been annoying me for hours.
Here's the call stack:
Code: Select all
kernel32.RaiseException
TMemDataSet.GetFieldDescNo + $71
TMemDataSet.SetFieldData + $19A
TDataSet.SetFieldData +$4B
TMemDataSet.SetFieldData + $3C
TField.SetData + $89
...
The code in OnCalcField is very simple:
Code: Select all
var
n: Integer;
begin
for n := 0 to DataSet.FieldCount - 1
do if DataSet.Fields[n].Calculated
then DataSet.Fields[n].AsBoolean := False
Any clue what could cause this?
Edit:
The calculated field is added before I do .Open -- when I call .Prepare before the call to FieldDefs.Update and adding the fields, the test application fails with the error message "Field not found." when this is not done, it works fine.
So, currently, this is what's done:
1) query with SQL statement
2) .Prepare
3) .FieldDefs.Update;
4) add calculated field
5) .Open
6) In OnCalcFields event: MyCalcField.AsBoolean := False;
Step 6 fails if step 2 is included, why?