as my topic.
how to dynamic to create the calc field in the virtua table??
Working with calculated fields in Virtual table is not different from BDE components. For example you can use next code:
Code: Select all
var
cfld : TFloatField;
implementation
procedure TForm1.Button1Click(Sender: TObject);
begin
//Assume that all fields are added to Fields list before.
VirtualTable1.Close;
cfld := TFloatField.Create(self);
cfld.FieldName := 'CalcFld';
cfld.Calculated := true;
cfld.DataSet := VirtualTable1;
VirtualTable1.Open;
end;
procedure TForm1.VirtualTable1CalcFields(DataSet: TDataSet);
begin
cfld.Value := DataSet.FieldByName('EmpNo').AsInteger + DataSet.FieldByName('Sal').AsInteger;
end;