0

I have a TClientDataSet which stores data coming from a medical instrument. This client dataset is linked to a grid to display data in real time. My problem is, when the user is editing the data, and the instrument sends a new packet, the data which the user has modified but not yet posted is lost because I only can get a TBookmark on current record, append the new record, and then goto the saved bookmark (which is sometimes not the correct record, apparently due to the new record). I can check dataset's State, Post if necessary, and then set the State afterwards, I'm looking for a way to update data in client dataset without affecting its State. Is this even possible?

iMan Biglari
  • 4,674
  • 1
  • 38
  • 83
  • Your q reads as if the new data from the instrument is being inserted by your app. Is that correct? – MartynA Oct 01 '13 at 08:15

1 Answers1

4

Clone the dataset and modify the data on the clone.

A document on it by Cary Jensen is here: http://edn.embarcadero.com/article/29416

Basically you need something like

var
  lEdDataset: TClientdataset;
begin
  lEdDataset := TClientDataSet.create(nil);
  try
    lEdDataset.CloneCursor(SourceDataSet, True**); 
    StoreMedDeviceRecord(lEdDataset);
  finally
    lEdDataset.free; 
  end;

** You'll need to read the documentation on the True/False settings and decide what you actually need (I can't remember off-hand)

Matt Allwood
  • 1,448
  • 12
  • 25
  • As a note to my own answer, it's also possible to just keep this clone open on the 'DeviceLogger' object rather than creating or freeing all the time. Whether this is a better solution or not depends on your app. – Matt Allwood Oct 01 '13 at 09:50
  • 1
    Don't forget that if the incoming data is being processed by a background thread, you'll need a synchronization object to serialize writes to the underlying data. – afrazier Oct 01 '13 at 16:53