>'m trying to attach a new calculated field to a TClientDataSet during
>runtime. Does anyone have an idea on how to do this ??
here is an example
2) In the FormCreate, create your calculated field:
(For this example,use DBDEMOS/EMPLOYEE.DB)
Table1.Active:=false; // Must be false to add Fields to the Dataset
Table1.FieldDefs.Update; // Make sure we have the latest Fields
Monthly:=TFloatField.Create(Table1);
Monthly.FieldName:='Monthly Salary';
Monthly.Calculated:=true;
Monthly.Dataset:=Table1;
Monthly.DisplayFormat:='$#,0.00';
Table1.Active:=true;
--
Brian Bushay (TeamB)
Bbu...@DataGuidance.com
Brian Bushay TeamB wrote in message
<35f3bc66...@forums.borland.com>...
I use a local client data set to contain the data provided by a SQL query.
ClientDataSet1 := TClientDataSet.Create( Application );
ClientDataSet1.Provider := sqlQry.Provider;
ClientDataSet1.OnCalcFields := SomeOnCalcFields;
sqlQry.Open;
ClientDataSet1.Open;
Is there any way to add a field to a dataset created this way or is there
any other approach that you recommend.
You have to have persistant fields to add a calculated field. You can create
the pesistant fields in code too.
Here is another example
var
f : TField;
i : integer;
begin
Table1.Close;
//itterate through fields and create persistant fields
for i := 0 to Table1.FieldDefs.Count - 1 do
Table1.FieldDefs.Items[i].CreateField(Table1);
//create new calculated field
f := TStringField.Create(Table1);
f.Name := 'Table1CalcField';
f.FieldName := 'CalcField';
f.DisplayLabel := 'CalcField';
f.Calculated := True;
f.DataSet := Table1;
//open the table for use
Table1.Open;
end;
Brian Bushay TeamB wrote in message
<35f0f0b1...@forums.borland.com>...