Search code examples
delphidelphi-xe7firedac

simple way to copy recordset from fdquery to fdquery


Using fireDac, is there a simpler way to copy FDQuery to FDQuery?

the current hardcoded solution is to map each field in code to eache other field in code and post and edit and such.

var
FDQueryThis,FDQueryOther:TFDQuery;
begin
  FDQueryThis.active:=true;
  FDQueryOther.active:=true;
  FDQueryThisNamelyField.AsInteger := FDQueryThis.NamelyField.AsInteger;
// some more fields
FDQueryThis.post;
end;

Is there a tool or a function that provide this service? I did see CopyRecord as a member of TFDQuery, howver how to create a record For TFDQuery?


Solution

  • I'd just use CloneCursor method,

    FDQueryThis.CloneCursor(FDQueryOther, True, False);
    

    Here You've got full description

    However keep in mind the physical data stays the same. if you want to copy the data to a different location use .Data property:

    FDQueryThis.Data := FDQueryOther.Data;
    

    Best regards