ClientDataSet 上的 StatusFilter
我在使用 ClientDataSet.StatusFilter := [usDeleted]
时遇到一些困难。
它没有任何作用。我正在将我的 ClientDataSet 连接到 Provider。
应用 StatusFilter 时,数据集不会显示已删除的记录。
它仅显示应用 StatusFilter 之前的记录。
另一方面。如果我使用未连接到提供程序的 ClientDataSet.CreateDataSet
且仅使用 ClientDataSet 作为内存中的数据集,则 StatusFilter 的工作方式如文档中所述。
DataSet仅显示已删除的记录。
ClientDataSet.UpdateStatus 还显示正确的状态 usDeleted。
我获得连接到提供程序以显示已删除记录的第一个 ClientDataSet 的唯一方法是使用 ClientDataSet.Delta 属性。但这不允许我恢复已删除的记录。
//Note: cds.LogChanges = true
cds := TClientDataSet.Create(nil);
cds.Data := MyClientDataSet.Delta;
cds.First;
while not cds.eof do
begin
case cds.UpdateStatus of
usModified:
begin
ShowMessage('Modified');
cds.RevertRecord;
end;
usInserted: ShowMessage('Inserted');
usDeleted: ShowMessage('Deleted');
end;
cds.Next;
end;
cds.Free;
我做错了什么?
I'm having some difficulties using ClientDataSet.StatusFilter := [usDeleted]
.
It doesn't do anything. I'm having my ClientDataSet hooked up to a Provider.
When applying the StatusFilter the DataSet does not display the deleted records.
It just shows the records as before applying the StatusFilter.
On the other hand. If I use ClientDataSet.CreateDataSet
which isn't hooked up to a provider and only use the ClientDataSet as an in-memory DataSet then the StatusFilter works as described in the documentation.
The DataSet only displayes the deleted records.
The ClientDataSet.UpdateStatus also shows the correct status usDeleted.
The only way I can get my first ClientDataSet that is hooked up to a provider to display the deleted records is by using the ClientDataSet.Delta property. But this doesn't allow me to Revert a deleted record.
//Note: cds.LogChanges = true
cds := TClientDataSet.Create(nil);
cds.Data := MyClientDataSet.Delta;
cds.First;
while not cds.eof do
begin
case cds.UpdateStatus of
usModified:
begin
ShowMessage('Modified');
cds.RevertRecord;
end;
usInserted: ShowMessage('Inserted');
usDeleted: ShowMessage('Deleted');
end;
cds.Next;
end;
cds.Free;
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您描述的代码
是在当前 ClientDataSet 视图中仅包含那些已删除的记录的正确方法。我不明白为什么它不适合你,因为我一直在我的代码中使用这种方法并且它从未失败过。我唯一能想到的是,您可能在设置 StatusFilter 属性之前调用了 ApplyUpdates 或 CancelUpdates,或者您可能将 LogChanges 设置为 False(默认值为 True)。
顺便说一句,要取消状态过滤器,请将其设置为空集,如下所示:
这将包括视图中插入的、已修改的和未修改的记录。删除的记录不会出现在当前视图中。
The code you describe
is the correct way to include in your current ClientDataSet view only those records that have been deleted. I do not understand why it is not working for you, as I use this approach in my code all the time and it has never failed. The only thing I can think of is that you may have called ApplyUpdates or CancelUpdates prior to setting the StatusFilter property, or you may have LogChanges set to False (it's default is True).
By the way, to cancel status filter set it to an empty set, like this:
That will include inserted, modified, and unmodified records in your view. The deleted records will not appear in the current view.