Assign TMyquery and calculated fields
Assign TMyquery and calculated fields
Im assigning a TMyquery to another TMyquery. Works fine until i try to access a calculated field - i get error "field XXX not found". I guess assign does not assign calculated fields, is there any workaround?
-
AndreyZ
Hello,
TMyQuery inherits basic functionality from the TDataSet class. The TDataSet.Assign method doesn't create fields in the destination dataset using fields from the source dataset. To solve the problem, you can use the following code:
TMyQuery inherits basic functionality from the TDataSet class. The TDataSet.Assign method doesn't create fields in the destination dataset using fields from the source dataset. To solve the problem, you can use the following code:
Code: Select all
procedure TMainForm.ButtonClick(Sender: TObject);
var
i: integer;
fld: TField;
begin
MyQuery1.Open;
MyQuery2.Assign(MyQuery1);
for i := 0 to MyQuery1.FieldCount - 1 do begin
fld := TFieldClass(MyQuery1.Fields[i].ClassType).Create(MyQuery2);
fld.FieldName := MyQuery1.Fields[i].FieldName;
fld.FieldKind := MyQuery1.Fields[i].FieldKind;
fld.DataSet := MyQuery2;
end;
MyQuery2.Open;
end;