Duplicating Table Records

This article was first published in Delphi Developer Magazine


{************************************************
// procedure AppendCurrent
//
// Written By: Steve Zimmelman
// 06/04/1996
//
// 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 the new record
  For i := 0 to (DataSet.Fieldcount-1) Do Begin
     DataSet.fields[i].Value := aField[i] ;
  End;
End;