delphitclientdatasetdelphi-11-alexandria

'Name not unique in this context' with design time CreateDataSet when fkInternalCalc fields present


I have a datamodule with several TClientDataSets with fields and field definitions, no provider.
My recent design time changes to all of these:

If there are one or more fields with FieldKind = fkInternalCalc, I get a 'Name not unique in this context' error.
Changing them to fkCalculated 'solves' the issue (but I had to check my OnCalcField handlers to make sure they also worked for State = dsCalcFields)

This is code that has gone through several Delphi versions, current is Alexandria 28.0.44500.8973
We have done modifications like this before, the datasets had Active=true when I started, and the form contained PersistDataPacket.Data blobs.

Is this a (new) Delphi bug or is there something about fkInternalCalc fields that I'm missing?


Solution

  • Remove all fields defined as fkInternalCalc from the FieldDefs collection before any call to CreateDataset (so also right-clicking 'Create dataset').

    I'm not sure if it's a bug or a feature, but CreateDataset tries to add fkInternalCalc fields to FieldDefs collection without checking whether it previously existed.

    If you have all the FieldDefs and corresponding Fields created, you can as well delete all items from FieldDefs collection, field definitions will be recreated.