Delphi:ResolveToDataset 问题
我正在使用 TClientDataset
以及提供程序的以下选项:
ResolveToDataSet = True
Options = [poPropogateChanges, poUseQuoteChar]
UpdateMode = upWhereKeyOnly
AfterUpdateRecord = DataSetProvider1AfterUpdateRecord
提供程序连接到 TIBCQuery 管理 NO_INVOICE
键的生成器。
在AfterUpdateRecord完成以下代码(如在组中的许多地方发现的那样,在发布到数据库时真正传播密钥更改)
DeltaDS.FieldByName(ClientDataSet1NO_INVOICE.FieldName).NewValue
:= SourceDS.FieldByName(ClientDataSet1NO_INVOICE.FieldName).NewValue
然后使用以下代码添加记录:
ClientDataSet1.Params[0].AsInteger := -1;
ClientDataSet1.Open;
ClientDataSet1.Edit;
ClientDataSet1NO_INVOICE.AsInteger := -1;
ClientDataSet1NO_STORE.AsInteger := 1;
ClientDataSet1.Post;
ClientDataSet1.ApplyUpdates(-1);
如果我调用 ClientDataSet1.Refresh 在ApplyUpdate,底层 TIBCQuery 重新打开,原始参数为 < code>-1 并且不使用新键 - 即使 ClientDataSet1NO_INVOICE.AsInteger
显示合并记录后分配的新值。
这里使用Refresh只是为了简化这个例子。当我们执行以下操作时会出现问题:
- 插入记录
- 应用更新
- 并再次编辑记录
我是否错过了使用 ResolveToDataset 选项,或者我应该使用新参数明确重新打开查询?
我之前在其他项目上使用 ResolveToDataset = False
时从未遇到过这个问题。
I am using a TClientDataset
with the following options for the provider:
ResolveToDataSet = True
Options = [poPropogateChanges, poUseQuoteChar]
UpdateMode = upWhereKeyOnly
AfterUpdateRecord = DataSetProvider1AfterUpdateRecord
The provider is connected to a TIBCQuery which manages the generator for the NO_INVOICE
key.
On AfterUpdateRecord the following code is done (as found in many places in groups to really propagate the key change when posting to the database)
DeltaDS.FieldByName(ClientDataSet1NO_INVOICE.FieldName).NewValue
:= SourceDS.FieldByName(ClientDataSet1NO_INVOICE.FieldName).NewValue
The following code is then used to add a record:
ClientDataSet1.Params[0].AsInteger := -1;
ClientDataSet1.Open;
ClientDataSet1.Edit;
ClientDataSet1NO_INVOICE.AsInteger := -1;
ClientDataSet1NO_STORE.AsInteger := 1;
ClientDataSet1.Post;
ClientDataSet1.ApplyUpdates(-1);
If I call ClientDataSet1.Refresh after the ApplyUpdate, the underlying TIBCQuery is reopened with the original param of -1
and not with the new key—even if the ClientDataSet1NO_INVOICE.AsInteger
shows up the new value assigned after merging records.
The use of Refresh here is only to simplify this example. The problems happens when we:
- insert a record
- apply updates
- and edit the record again
Did I miss something with the usage of the ResolveToDataset option, or should I explicitly reopen the query with the new param?
I never had this problem before when using ResolveToDataset = False
on other projects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论