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?

有帮助吗?

解决方案

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)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top