Delphi:应用更新时访问嵌套数据集主信息

发布于 2024-11-12 22:16:58 字数 832 浏览 1 评论 0原文

将更新应用到嵌套数据集时,我可以在提供程序的 BeforeUpdateRecord 事件中访问父数据集信息(例如 MyField.NewValue)吗?

原因:

当我将更新应用于具有嵌套详细信息的 CDS 时,主 PK 由基础查询 (TIBCQuery) 生成并传播到主 CDS。

但新键在详细信息的 BeforeUpdateRecord 中不可见,因为该字段在 AfterUpdateRecord 中更新:

DeltaDS.FieldByName(FieldName).NewValue := SourceDS.FieldByName(FieldName).NewValue) 

并且增量尚未合并。

当调用详细信息时,BeforeUpdateRecord 事件的 DeltaDS 参数看起来仅包含嵌套数据集的信息。

如果我可以执行以下操作,那就太好了:

DeltaDS.ParentDS.FieldByName('FIELDNAME').NewValue.

编辑:

当使用嵌套数据集时,BeforeUpdateRecord 事件被调用两次,一次用于主数据,一次用于详细数据(如果我们两者都有一份记录)。当调用详细信息事件时,有没有办法访问 DeltaDS 中包含的主信息?

此时我们无法访问主 CDS 的数据,因为更改尚未合并。我希望这不会增加更多的混乱。

Can I access the parent dataset information (like MyField.NewValue) in the BeforeUpdateRecord event of a provider when applying the updates to the nested dataset?

Reason:

When I apply updates to a CDS that has a nested detail, the master PK is generated by the underlying query (TIBCQuery) and propagated to the master CDS.

But the new key is not visible in the BeforeUpdateRecord of the detail as the field is updated in the AfterUpdateRecord:

DeltaDS.FieldByName(FieldName).NewValue := SourceDS.FieldByName(FieldName).NewValue) 

and the delta is not merged yet.

It looks like the DeltaDS parameter of the BeforeUpdateRecord event contains only information to the nested dataset when the call occurs for the details.

It would be nice if I could do something like:

DeltaDS.ParentDS.FieldByName('FIELDNAME').NewValue.

Edit:

When using nested datasets the BeforeUpdateRecord event is called twice, once for the master and once for the detail (if we have one record of both). When the event is called for the detail, is there a way to access the master information contained in the DeltaDS ?

We can't access the data of the master CDS at that moment as the changes are not already merged. I hope this is not adding more confusion.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纸伞微斜 2024-11-19 22:16:58

您可以使用提供程序的 Resolver 查找相应的 TUpdateTree

function FindDeltaUpdateTree(Tree: TUpdateTree; DeltaDS: TCustomClientDataSet): TUpdateTree;
var
  I: Integer;
begin
  Result := nil;
  if Tree.Delta = DeltaDS then
    Result := Tree
  else
    for I := 0 to Tree.DetailCount - 1 do
    begin
      Result := FindDeltaUpdateTree(Tree.Details[I], DeltaDS);
      if Assigned(Result) then
        Break;
    end;
end;

您可以在 OnBeforeUpdate 处理程序中使用它:

var
  Tree, ParentTree: TUpdateTree;
begin
  if SourceDS = MyDetailDataSet then
  begin
    Tree := FindDeltaUpdateTree(TDataSetProvider(Sender).Resolver.UpdateTree, DeltaDS);
    if Assigned(Tree) then
    begin
      ParentTree := Tree.Parent;
      // here you can use ParentTree.Source (the dataset) and ParentTree.Delta (the delta)
    end;
  end;
end;

You can use the provider's Resolver to look up the corresponding TUpdateTree:

function FindDeltaUpdateTree(Tree: TUpdateTree; DeltaDS: TCustomClientDataSet): TUpdateTree;
var
  I: Integer;
begin
  Result := nil;
  if Tree.Delta = DeltaDS then
    Result := Tree
  else
    for I := 0 to Tree.DetailCount - 1 do
    begin
      Result := FindDeltaUpdateTree(Tree.Details[I], DeltaDS);
      if Assigned(Result) then
        Break;
    end;
end;

You can use this in your OnBeforeUpdate handler:

var
  Tree, ParentTree: TUpdateTree;
begin
  if SourceDS = MyDetailDataSet then
  begin
    Tree := FindDeltaUpdateTree(TDataSetProvider(Sender).Resolver.UpdateTree, DeltaDS);
    if Assigned(Tree) then
    begin
      ParentTree := Tree.Parent;
      // here you can use ParentTree.Source (the dataset) and ParentTree.Delta (the delta)
    end;
  end;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文