DataSnap服务器生成的ID自动更新到客户端

很久没有去动Delphi了,突然兴起做个小程序,一个表的ID,在服务器端的应用服务器上生成,如何刷新到客户端?

查看了TDataSetProvider的Options属性,比以前增加了一个poPropogateChanges,解释如下:

Changes made by the server to updated records as part of the update process are sent back to the client and merged into the client dataset.

代码在服务器端TDataSetProvider的BeforeUpdateRecord事件中,生成ID,如下:

    if UpdateKind = ukInsert then
      DeltaDS.FieldByName('DRUG_INFO_ID').AsInteger:= GetPrimaryKey('T_DRUG_INFO','DRUG_INFO_ID');
   

客户端ApplyUpdates(0) 后,发现ID仍然没有更新,百思不得其解,后来将AsIneger改成NewValue,一切就好了,真是无语....

  if UpdateKind = ukInsert then
        DeltaDS.FieldByName('DRUG_INFO_ID').NewValue := GetPrimaryKey('T_DRUG_INFO','DRUG_INFO_ID');

原文地址:https://www.cnblogs.com/mikemao/p/3145419.html