DelphiFAQ Home Search:

Copy the current record of a dataset

 

comments12 comments. Current rating: 5 stars (5 votes). Leave comments and/ or rate it.

I found this routine which copies the current record of the currently selected record. This is useful e.g. to keep a temporary record for display in a form.


{************************************************
// procedure AppendCurrent
//
// Written By: Steve Zimmelman
// 6/4/96
//
// Version: Delphi 2.0
//
// Will append an exact copy of the current
// record of the dataset that is passed into
// the procedure and will return the dataset
// in edit state with the record pointer on
// the currently appended record.
************************************************}
procedure AppendCurrent(Dataset:Tdataset);
var
  aField : Variant;
  i      : Integer;
begin
  // Create a variant Array
  aField := VarArrayCreate(
               [0,DataSet.Fieldcount-1],
                             VarVariant);
  // read values into the array
  for i := 0 to (DataSet.Fieldcount-1) do
  begin
     aField[i] := DataSet.fields[i].Value ;
  end;
  DataSet.Append ;
  // Put array values into new the record
  for i := 0 to (DataSet.Fieldcount-1) do
  begin
     DataSet.fields[i].Value := aField[i] ;
  end;
end;

Content-type: text/html

Comments:

2007-05-28, 16:08:11
anonymous from Debrecen, Hungary  
rating
Small and practical, I was exactly in need for it.
2008-01-18, 11:00:11
anonymous from Argentina  
┬┐Field readOnly As Autoincremet? For example Identity
2009-04-15, 05:35:59
anonymous from Ukraine  
thanks, exactly what i am looking for
2009-05-24, 16:06:49
anonymous from Portugal  
Very nice

But how can i duplicate de Subfieldes os the Master Table i use Ado

Rebotea@gmail.com
2010-04-08, 04:34:17
Gianpiero Caretti from Italy  
rating

Field readOnly As Autoincremet? For example Identity


filter them using the CanModify property:

// Put array values into new the record
for i := 0 to (DataSet.Fieldcount-1) do
begin
if (DataSet.fields[i].CanModify) then
DataSet.fields[i].Value := aField[i] ;
end;

2012-04-14, 13:48:15
Abdallah  
rating
thank you very much , that's what i was searching
2013-02-11, 22:56:03
Randeep from New Zealand  
rating
I used cloneCursor and worked brilliantly.
2014-03-18, 09:13:46
anonymous from India  
Not Working.

Variant arrays of custom variants are not supported, as instances of custom variants can be added to a VarVariant variant array.
2014-06-30, 06:18:23
anonymous from United States  
What database do you have. I have MS SQL 2005 and it works for me.
2014-06-30, 06:18:23
anonymous from United States  
What database do you have. I have MS SQL 2005 and it works for me.
2014-06-30, 06:21:57
anonymous from United States  
Also, make sure you edit the original post with this.
// Put array values into new the record
for i := 0 to (DataSet.Fieldcount-1) do
begin
if (DataSet.fields[i].CanModify) then
DataSet.fields[i].Value := aField[i] ;
end;
2014-11-06, 07:53:25
anonymous from Netherlands  
rating

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: