Easiest way to copy a record with TOracleDataset

Jan

Member
Hi all.

How do i copy a record with all its fields ?

I want to make an exact copy except for a unique field "ID" which is updated by a sequence - controlled by TOracleDataset Sequencefield.
I want to get the ID of the new record returned immediately after the copy.

Rgds
Jan
 
To copy all field values except the one that gets its value through a sequence, you can use the following code:
Code:
procedure TMainForm.CopyButtonClick(Sender: TObject);
var Values: Variant;
    f: Integer;
begin
  with MyDataSet do
  begin
    Values := VarArrayCreate([0, Fields.Count - 1], varVariant);
    for f := 0 to Fields.Count - 1 do Values[f] := Fields[f].Value;
    Append;
    for f := 0 to Fields.Count - 1 do
      if CompareText(SequenceField.Field, Fields[f].FieldName) <> 0 then
        Fields[f].Value := Values[f];
  end;
end;
If SequenceField.ApplyMoment = amOnNewRecord, then the new record will immediately contain a fresh value generated by the sequence.

------------------
Marco Kalter
Allround Automations
 
Back
Top