Re:How to copy/duplicate a record in a TTable
Create a table object, point it to the original table, and sychronize
(GoToCurrent)
place original table in insert mode, iterate through tempory table
for i := 0 to TempTable.FieldCount -1 do begin
OriginalTable.FieldbyName(TempTable.Fields[i]).Assign(TempTable.Fields[i]);
end;
Caveats..
You need the "FieldByName" syntax as you cannot assume that the
field order of the two datasets is the same.
This will try and copy all fields. One exception may be raised
during execution if you try to assign to an autoinc field, onother will
be raised at post because you will have duplicate keys.
to deal with this I normally use GetFieldNames and delete the names of
fields that I dont want copied and then use this loop
for i := 0 to MyFieldList.Count -1 do begin
OriginalTable.FieldbyName(MyFieldList[i]).Assign
(TempTable.FieldByName(MyFieldList[i]));
end;
This works but is not exactly abstract.
I'd love to here a better way myself.
Hope this helps...
Steve Griffiths.
Quote
John Olliver wrote:
> I need to be able to copy/almost duplicate the current record in a
> TTable
> (Paradox 5.0 Table).It must be dead simple or so I thought 24 hrs ago
> Amongst other things I have tried:
> ----------------------------------------
> for x:=0 to Table1.fieldcount-1 do
> begin
> with Table1.fields[x] do
> begin
> GetMem(Mybuffer,datasize);
> GetData(buffer);
> MyArray[x]:=(buffer);
> end;
> end;
> Table1.Edit;
> Table1.Setfields(MyArray) ;
> -----------------------------------------
> I understand that Setfields takes an Array of Const but I can?t seem
> to declare
> MyArray as an Array of Const. If I declare it as an array of String
> (say) then
> Setfields {*word*88}s on it. And if I could declare MyArray as an array of
> const how
> would I pass the field data into it. Can I pass the (buffer) from
> GetData(buffer,datasize) into MyArray ? (And what is the meaning of
> life.)
> Or perhaps there?s a completely better way. Now spent over a day on
> this and
> nothing seems to work so any help much appreciated.
> John Olliver