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:
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:
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:
uses
DB, DBCommon, DBClient, DSIntf;
type
THackClientDataSet = class(TClientDataSet);
procedure EncodeFieldDesc(var FieldDesc: DSFLDDesc;
const Name: string; DataType: TFieldType; Size, Precision: Integer;
Calculated: Boolean; Attributes: TFieldAttributes);
begin
// ... copied from TClientDataSet.EncodeFieldDesc
end;
//...
var
FldDesc: DSFLDDesc;
begin
FillChar(FldDesc, SizeOf(FldDesc), 0);
EncodeFieldDesc(FldDesc, 'SELECTED', ftBoolean, 0, 0, False, []);
with THackClientDataSet(DataSet) do
Check(DSBase.AddField(@FldDesc));
// now you can create a second client dataset and assign it DataSet.Data directly:
// DataSet2.Data := DataSet.Data;
// DataSet2 now contains the new field (with empty values in all existing records)
end;
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.