Again I have a problem with the TClientDataSet. I guess it's something really simple but I struggle on it for a while now.
Here's some code what shows what I want to do:
procedure TForm1.Button1Click(Sender: TObject);
begin
ClientDataSet1.Insert;
ClientDataSet1.FieldByName('anruf_von').AsDateTime := time;
ClientDataSet1.Post;
ClientDataSet1.ApplyUpdates(0); // without this applyUpdates in button2 works.
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ClientDataSet1.edit;
ClientDataSet1.FieldByName('anruf_bis').AsDateTime := time;
ClientDataSet1.Post;
showmessage(intToStr(ClientDataSet1.ChangeCount)); // returns 1
if ClientDataSet1.ChangeCount > 0 then
ClientDataSet1.applyUpdates(0);
end;
The code is self explaining I think. When I press button1, a record is created and after the call to applyUpdates its written to the databse. When I press button2, I want to make a change to this record and apply the updates to the database - and that doesn't work. But when I comment out the applyUpdates in button1, the applyUpdates in button2 works correctly.