Author: Tomas Rutkauskas
Copy the current record of a dataset
Answer:
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.
1 2 {************************************************3 // procedure AppendCurrent4 //5 // Will append an exact copy of the current6 // record of the dataset that is passed into7 // the procedure and will return the dataset8 // in edit state with the record pointer on9 // the currently appended record.10 ************************************************}11 12 procedure AppendCurrent(Dataset: Tdataset);
13 var14 aField: Variant;
15 i: Integer;
16 begin17 // Create a variant Array18 aField := VarArrayCreate(
19 [0, DataSet.Fieldcount - 1],
20 VarVariant);
21 // read values into the array22 for i := 0 to (DataSet.Fieldcount - 1) do23 begin24 aField[i] := DataSet.fields[i].Value;
25 end;
26 DataSet.Append;
27 // Put array values into new the record28 for i := 0 to (DataSet.Fieldcount - 1) do29 begin30 DataSet.fields[i].Value := aField[i];
31 end;
32 end;