Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Copy dataset record to new record
Thu, Jun 9 2016 6:33 PMPermanent Link

Trinione

Anyone know how to copy the existing dataset record to a new record?

I was thinking I could copy the fields to an array, ds.Insert(true), then loop thru the array and assign the value via ds.Columns[i].Assign(aValue[i]);

As in:
------------------------------------------------------------
var
 aValue: variant;

begin
 // Create a variant array
 SetLength(aValue, ds.ColumnCount - 1);

 // read values into the array
 for i := 0 to (ds.ColumnCount - 1) do
 begin
   aValue[i] := ds.Columns[i];
 end;

 // append a new record
 ds.Insert(true);

 // Put array values into new record
 for i := 0 to (ds.ColumnCount - 1) do
 begin
   ds.Columns[i].Assign(aValue[i]);
 end;
------------------------------------------------------------

Though no error messages appear, when another form includes the form this code is on I get a 'Compilation
Fri, Jun 10 2016 3:42 AMPermanent Link

Matthew Jones

Trinione wrote:

> Though no error messages appear, when another form includes the form
> this code is on I get a 'Compilation

Knowing the error would help! 8-)

--

Matthew Jones
Fri, Jun 10 2016 5:30 AMPermanent Link

Uli Becker

SetLength(aValue, ds.ColumnCount - 1);

Should be

SetLength(aValue, ds.ColumnCount);

Uli
Fri, Jun 10 2016 7:44 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com


<< Anyone know how to copy the existing dataset record to a new record? >>

You normally should use the Assign method:

http://www.elevatesoft.com/manual?action=viewmethod&id=ewb2&comp=TDataValues&method=Assign

(TDataRow descends from TDataValues)

However, that will also copy the row ID, which you don't want to do.  So, I'll have to add a parameter to indicate whether you want to copy the row ID and the row values, or just copy the row values.

Tim Young
Elevate Software
www.elevatesoft.com
Fri, Jun 10 2016 11:29 AMPermanent Link

Trinione

<< You normally should use the Assign method:
http://www.elevatesoft.com/manual?action=viewmethod&id=ewb2&comp=TDataValues&method=Assign

(TDataRow descends from TDataValues)

However, that will also copy the row ID, which you don't want to do.  So, I'll have to add a parameter to indicate whether you want to copy the row ID and the row values, or just copy the row values. >>


Tim:
The two dataset approach came to me as the simplest solution, and the Assign method fits right up that alley. And I was wondering about how the ID field/s would be ignored.

Is there a simple HotFix in the meantime? If not, I can just wait. (Don't want to distract the 2.05 rollout).
Image