Jump to content
Ian Branch

Copy a record from TTable to kbmMemTable??

Recommended Posts

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

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

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

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

  • Like 1

Share this post


Link to post

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×