Scalabium Software

SMReport Autogenerated
Knowledge for your independence'.
Home Delphi and C++Builder tips

#63: How can I copy (dublicate) the dataset record?

In some apllications, in which user must add a lot of the records in the dataset, very useful the "copy record" mode.

For example, the operator added the new record and must add the new, but this second record is "similar" to first and only few attributes are different. In this case, I use the possibility to dublicate the values of the wished record, insert a new record and open the dialog for editing these values.

Those from you, who uses the my freeware TSMDBNavigator component, saw the new additional Copy button with the next handler:

procedure TSMDBNavigator.CopyRecord;
var varCopyData: Variant;
    i: Integer;
  with DataSource.DataSet do
    varCopyData := VarArrayCreate([0, FieldCount-1], varVariant);
    for i := 0 to FieldCount-1 do
      varCopyData[i] := Fields[i].Value;


    for i := 0 to FieldCount-1 do
      Fields[i].Value := varCopyData[i];

So you can assign to the TSMDBNavigator.OnEditRecord event the dialog opening for record edit. In this event I pass the second parameter: is copy mode or edit mode only.

Of course, you can cut this procedure and use this code for run-time record dublication without using TSMDBNavigator component. Also you can modify it and exclude the wished fields (for example, autoincremental fields).

Published: January 26, 2000

See also
Fast Document Viewer
Excel Reader (dll)
DBExport tools
ExcelFile Viewer
Paradox ActiveX
ABA Database Convert
ABA Document Convert

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2023, Scalabium Software. All rights reserved.

SMExport advertising