CopyRecordSet and calculated fields

My scenario is that I’m trying to create a duplicate of a TDAMemDataTable at runtime.

The source table has calculated fields. It’s in a data module with BusinessRulesID property set correctly so the business rules class’s OnCalcFields event handler correctly populates the calculated fields, all fine.

Now, at runtime, I want to create a new TDAMemDataTable and copy all data to it. To this end I’m simply using CopyRecordSet.

This works in that it duplicates all the fields and copies all records across, except the calculated fields in the new table are all blank. I need them populated.

Option one is to have the destination fields be ‘regular’ (i.e. non-calculated fields) which contain the same values as the calculated fields of the same name in the source table.
This feels very cumbersome as I’d have to manually iterate every field of every row and manually copy the value across.

Option two is to somehow create an instance of the business rules class for the destination table so the calculated fields are calculated in the same way as the source.
This feels cleaner but I can’t make it work. Setting the BusinessRulesID property of the destination table immediately after creation appears to create the business rules class and assign it to BusinessEventsObj but the calculated fields still don’t work and the values are empty after the call to CopyRecordSet.

Any ideas?


Can I ask why you should duplicate table?

In some cases, when you don’t need to change values, you can use cloned tables. these tables share main table’s recordset with all clones. these tables (main and clones) can have personal sorting, filtering, position and can be used in master/details relationships, as a lookup sources

check more at Cloned Source sample (desktop) (Delphi)