Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:40:14+00:00 2026-06-15T03:40:14+00:00

Precis: My code is attempting to update non-physical fields in a Delphi XE TClientDataset

  • 0

Precis: My code is attempting to update non-physical fields in a Delphi XE TClientDataset, (connected to a TSQLQuery with its SQL property set) that were created as result of a runtime Open command.

I have a TClientDataset connected to a TDatasetProvider connected to a TSQLQuery connected to a TSQLConnection. The first 3 of these objects are encapsulated within a couple of classes in a library that I use in many places on several projects. These classes create these 3 objects at runtime and eliminate a significant amount of repetitious code, necessary as I have many, many of these triplets.

Quite typically I will load the TClientDataset from a database by specifying some SQL in the SQL property of the TSQLQuery and calling Open on the TClientDataSet. The Fields in the TClientDataset are created via this call to Open ie. they don’t exist prior to Open.

I have run into a problem in a situation where three of the fields generated into the TClientDataset are non-physical; that is, the SQL does calculations to generate them. Unfortunately, in the TClientDataset, these 3 fields do not get created any differently to the physical fields; their FieldKind is fkData (ideally it would be fkInternalCalc), Calculated property is False (ideally it would be True) and their ProviderFlags include pfInUpdate (which ideally it should not). Not surprisingly, when it comes time to do an ApplyUpdates on the TClientDataset an exception is thrown…

Project XXX.exe raised exception class TDBXError with message
SQL State: 42S22, SQL Error Code: 207 Invalid column name 'Received'.
SQL State: 42S22, SQL Error Code: 207 Invalid column name 'Issued'.
SQL State: 42S22, SQL Error Code: 207 Invalid column name 'DisplayTime'.

I can avoid this error by clearing these field’s pfInUpdate flags in the TDatasetProvider‘s OnUpdateData event handler. However this solution requires that the specific field names be known to this function which sits in the generic classes mentioned above, thus breaking the code’s generality.

What I am looking for is a generic means of signalling the calculated nature of these fields to the event handler function.

I cannot change their FieldKind or Calculated properties (to fkInternalCalc and True respectively) after the Open call as this generates a WorkCDS: Cannot perform this operation on an open dataset exception message. And, I cannot change these properties before the Open call since the Fields do not exist yet.

I can remove the pfInUpdate flag from these Field‘s ProviderFlags properties after Open but this does not get passed onto the “Delta” TClientDatset that arrives at the OnUpdateData event handler. I also tried setting the field’s FieldDefs.InternalCalcField properties; again this does not get passed to the Delta dataset.

So, all the signalling ideas that I have tried have not worked. I would be grateful for any new ideas or an alternate approach.

All of the internet search results that I have encountered – including Cary Jensen’s excellent articles – deal with design-time or non-SQL generated setups that do not apply to my situation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:40:16+00:00Added an answer on June 15, 2026 at 3:40 am

    You can create a mechanism in your class to pre-configure the ProviderFlags for the individual fields you want to ignore in your Update process.

    As per the comments on your question, I’m suggesting you to create a new method in the class to open the inner ClientDataSet, all the magic will take place inside this method.

    First, one simple mechanism is to include a new TStringList property which lists all the fields you want to ignore, that you will match by name. Feel free to adopt this or create a new better mechanism, the important thing is you’re able to identify which fields you want to configure that way.

    type
      TMyClass = class
        // all your current class here
      private
        FUpdateIgnoredFields: TStringList;
      public
        property UpdateIgnoredFields: TStringList read FUpdateIgnoredFields write SetUpdateIgnoredFields;
        //don't forget to create this in your constructor, free it in the destructor
        //and Assign any new value in the SetUpdateIgnoreFields method, as usual.
        procedure OpenInnerCDS; //the magic goes here
      end;
    
    procedure TMyClass.OpenInnerCDS;
    var
      FieldName: string;
      AFieldToIgnore: TField;
    begin
      //opens the inner cds, but before that, configures the update-ignored  
      //fields in the underlying dataset
      //Let's call it InnerBaseDataSet;
      FInnerBaseDataSet.Open; //this opens the DataSet and creates all the fields for it.
      try
        for FieldName in FUpdateIgnoredFields do
        begin
          AFieldToIgnore := FInnerBaseDataSet.FindField(FieldName);
          if Assigned(AFieldToIgnore) then
            AFieldToIgnore.ProviderFlags := AFieldToIgnore.ProviderFlags - [pfInUpdate, pfInWhere];
        end;
        //now, let's open the ClientDataSet;
        FInnerClientDataSet.Open;
      finally
        //I suggest no matter what happens, always close the inner data set
        //but it depends on how the CDS->Provider->DataSet interaction is configured
        FInnerBaseDataSet.Close;
      end;
    end;
    
    //the way you use this is to replace the current ClientDataSetOpen with something like:
    
    var
      MyInsance: TMyClass;
    begin
      MyInstance := TMyInstance.Create();  //params
      try
        //configuration code here
        //MyInstance.InnerCDS.Open;  <-- not directly now
        MyInstance.UpdateIgnoreFields.Add('CALCULATED_SALARY');
        MyInstance.OpenInnerCDS;
        //use the CDS here.
        MyInstance.InnerCDS.ApplyUpdates(-1); //safely apply updates now.
      finally
        MyInstance.Free;
      end;
    end;
    

    Take it as a idea.

    I wrote all the code here, maybe the syntax is wrong, but it shows the whole idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I write JavaScript code and I try to use its functional language nature. In
Code is much more precise than English; Here's what I'd like to do: import
Code snippet to follow. I have a struct (example code has class, tried both,
This may be very obvious question, pardon me if so. I have below code
I have seen some repeated code (methods to be precise) where they are entering
I want to use precise layout on Nexus One, my code is like this:
I am calling Lucene using the following code (PyLucene, to be precise): analyzer =
I am porting some legacy code from windows to Linux (Ubuntu Karmic to be
Doing a small project I have received some Java code that I should rewrite
I have a code that I want to optimise that should run in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.