I have an custom TDatasetProvider that allows to create new fields to whatever data it provides.
So, let's say you got the folowing fields on the original dataset:
- CustomerId
- Name
- Age
And you need to select it on DBGrid using showing an Bitmap. Well, you can since my DSP can add
an boolean field called Selected
to the dataset data.
The way I do that now:
- Create 2 TClientDataset objects (Origin and Target)
- In Origin, I load the data got from the parameters of the InternalGetRecords method (I overrode it)
- In Target, I create the fielddefs defined from the Origin dataset and add the fielddefs created in design-time by the developer
- Execute an CreateDataset on Target
- And, row-by-row (and field-by-field), I copy the data from the Origin database to the Target dataset
- In the end, return the Data variant as a return value from InternalGetRecords.
I really don't know if there's a more elegant (and faster) way to do that. There's another (faster and/or elegant) way to get that result?
It seems that after loading the data from the source dataset, you can call
IDSBase.AddField
to add more fields:I didn't test it thoroughly but the simple example above worked as expected, I was able to navigate the second client dataset and edit the values of all fields as usual.