Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I implement "writable calculated" fields in a TDataSet?

I am in the need to add additional fields to a TDataSet that don't exist in the underlying database but can be derived from existing fields. I can easily do this with caclulated fields and that works perfectly.

Now I want to edit these fields and write the changed data back. I can reverse the calculation to write the data back into the existing fields, but the DB controls just don't let me edit calculated fields.

Is there any approach that allows me to do this?

Update: Ok, some more details about the background.

The dataset has a blob field, which is a TBytes representation. Some of the bytes are identified to contain information that can be represented in a convenient way with existing DB edit fields. Not all of the bytes are known, though, so the TBytes representation has to be kept as it is for processing through another application that knows about it. This app also modifies existing and inserts new records.

The TBytes of different records in the dataset often map to different fields representations, although setting a filter or range on the dataset will ensure that they have the same mapping.

As I said, extracting the known bytes and convert it into strings, dates, numbers and so on via calculated fields is no problem. Reconverting those values into the TBytes is also possible. The problem is making those extra fields editable, while keeping the dataset navigation intact.

If it helps: We have classes that do the bidirectional mapping, exposing the fields as published properties.

like image 537
Uwe Raabe Avatar asked Mar 18 '11 11:03

Uwe Raabe


1 Answers

The answer depends on a data access components you are using. I am using Anydac and it support fkInternalCalc fields, which may be as calculated as manually edited.

like image 95
GeorgeJ Avatar answered Sep 22 '22 11:09

GeorgeJ