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

  • SEARCH
  • Home
  • 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 631873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:00:52+00:00 2026-05-13T20:00:52+00:00

Scenerio: I want to add a calculated field to given (any) dataset during runtime.

  • 0

Scenerio:

I want to add a calculated field to given (any) dataset during runtime. I don’t know any other way to obtain a dataset structure other than performing DataSet.Open method.

But the Open method causes that atleast one row of a data needs to be transfered from server to client. Then I need to close the DataSet, add field and reopen it. This is an unnecessery overhead in my opinion. Is there a better way of doing this? Please not that I want to be able adding a calcuated field to any dataset and I don’t know its structure prior to opening.

In pseudocode it looks like this:

DataSet.Open;
DataSet.Close;
RecreateFieldsStructure;
AddCalculatedField;
DataSet.Open;

Thanks for your time.

  • 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-05-13T20:00:53+00:00Added an answer on May 13, 2026 at 8:00 pm

    You can use DataSet.FieldDefs.Update method. This will still involve some data transfer but no rows will be fetched. You can call this method in the BeforeOpen event of the TDataSet and also add the calculated fields there.

    Here’s a short example that works for me:

    procedure TDataModule.cdsExampleBeforeOpen(DataSet: TDataSet);
    var I: Integer;
        TmpField: TDateTimeField;
    begin
      // Get field definitions from the server
      DataSet.FieldDefs.Update;
    
      // Add calculated field
      TmpField := TDateTimeField.Create(DataSet);
      with TmpField do
      begin
        Name := 'Date';
        FieldName := 'Date';
        DisplayLabel := 'Date';
        DisplayFormat := 'ddd ddddd';
        Calculated := True;
      end;
      TmpField.DataSet := DataSet;
    
      // Create fields from field definitions
      for I := 0 to DataSet.FieldDefs.Count - 1 do
        DataSet.FieldDefs[I].CreateField(DataSet);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When you want to add some extra information into a class, what way would
I want to add a button to an asp page. The scenario is: If
I have a scenario where I want to dynamically add words of text to
I have a scenario that i want to add some standard properties to my
i am having dynamically created UITableView . I want to add 3 dummy row
How do I add a new key in the registry of other users using
I have a tricky scenario whereby I want to add ScriptManager scriptreference only on
Scenario: we already have a Document model, and we want to add public private
I'm working on project and main layout contains ListView. I want to dynamically add
I want to add attributes (like Browsable(false)) dynamically while displaying in the grid. Scenario

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.