I want to create a 'fake' data field in a DataSet (not ClientDataSet):
I know I can have a simple no-dbaware control, capture it's OnChange event and perform the calculations there (or call a DataModule function, where the DataSet resides) but I think it's more clean if I can reutilize the dataset automatic binding with db-ware controls and dataset events..
Also this way the unique connection between the Form (Presentation) and the DataModule (Model) it's the DataSet (less coupling)..
PD: I'm using fibplus, with I think the solution (if any) will be at the VCL level..
Thanks!
Have you tried using an InternalCalc field? Your data aware controls will let you edit an InternalCalc field's value, and the value is stored in the dataset.
If you create an InternalCalc field in the dataset (TClientDataSet, TQuery, etc.) at design time, it's almost exactly what you're asking for.
You could create an updatable view (with before insert/update/delete triggers) in your Interbase/Firebird database. This would look like a "virtual table" to the client (the select statement of the view's declaration can also contain "virtual fields") and it's totally up to you how you implement the triggers.
You can make a Calcfield writeable:
type
TCalcStringField = class(TWideStringField)
function GetCanModify: Boolean; override;
end;
function TCalcStringField.GetCanModify: Boolean;
begin
// Makes Calcfield editable
//if FieldNo > 0 then
if DataSet.State <> dsSetKey then
Result := not ReadOnly and DataSet.CanModify
else
Result := IsIndexField
//else
// Result := False;
end;
Set Calculated to true, and in OnSetText of this Field you can then write the Text to any other place
procedure TformXX.XXOnSetText(Sender: TField; const Text: string);
begin
...
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With