Ian Branch 127 Posted December 23, 2021 Hi Guys, I'm going around in circles with this. As the title suggests, I want to copy a single record from an ElevateDB TEDBTable to a TkbmMemTable. I have the structure copied using.. kbmMemTable.CreateTableAs(MyTEDBTable, [mtcpoStructure, mtcpoProperties]); But I can't figure how to later copy a single record as desired. kbmMemTable has a CopyRecord function but that only seems to work between two kbmMemTables. :-( A solution would be greatly appreciated. Regards & TIA, Ian Share this post Link to post
Lajos Juhász 293 Posted December 24, 2021 Maybe you should try the old way. Append the memtable and set the value for the fields. Depending if you have only couple of fields you can write an the assign statements otherwise use a for loop. Something like this should work (you're copying the structure thus the order of the fields should be the same): var i: integer; begin kbmMemTable.Append; for i:=0 to kbmMemTable.fieldCount-1 do kbmMemTable.fields.value:=myTEDBTable.fields.value; end; Share this post Link to post
Uwe Raabe 2057 Posted December 24, 2021 TDataSet offers a method CopyFields for that. Share this post Link to post
Ian Branch 127 Posted December 24, 2021 Hi Team, Merry Christmas to All. I have ended up with the following... function CopyRecord(tblFrom: TEDBTable; tblTo: TkbmMemTable; const StartIndex: Integer = 0): Boolean; var i: Integer; FieldFrom, FieldTo: TField; begin Result := False; for i := StartIndex to tblFrom.FieldCount - 1 do begin FieldFrom := tblFrom.Fields[i]; FieldTo := tblTo.FindField(FieldFrom.FieldName); if Assigned(FieldTo) then begin FieldTo.Value := FieldFrom.Value; Result := True; end; end; end; Thank you all for your input/suggestions. Regards, Ian Share this post Link to post
Kim Madsen 4 Posted December 31, 2021 kbmMemTable contains several methods for copying from other TDatasets. One is CopyRecords. mt.CopyRecords(sourceds,mt,1,'',false); Or if you yourself has an editable/appended/inserted record spot available on the destination, you can use AssignRecord(sourceds, destds); Both will automatically figure out which fields to copy. CopyRecords will even allow you to map fields to other field names if needed. mt.CopyRecords(sourceds,mt,1,'fld1a=fld1b;fld2a=fld2b',false); Fields in source table fld1a and fld2a is mapped to destination table fields fld1b and fld2b. /Kim 1 Share this post Link to post
Ian Branch 127 Posted December 31, 2021 Thanks Kim, I actually eliminated the need to copy to the kbmMemTable. I did look at mtCopyRecord but there was no Help Description. I didn't think of looking at mtCopyRecords. My Bad. I will keep this piece of info for any later use. Regards, Ian Share this post Link to post