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.
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: