如何确定何时将记录插入到 TDataSet 中?
我正在编写一个网格控件,它将显示 TDataSet 或 TObjectList 的内容。当您只需要支持 TDataSet 时,事情非常简单:
- 通过 TDataLink 后代链接到数据集。
- 当绘制网格的内容时,您可以使用 TDataLink 中缓冲的记录来绘制您需要的内容。
- 不需要在某个地方有单独的对象来表示 TDataSet 中的行,因为您总是只在缓冲区中绘制行。
就我而言,我还需要接受来自其他一些源的数据,这意味着我需要一个代表每一行的对象(也因为控件需要相当多的行状态)。
但这会导致上述模型出现问题。因为我有一个代表每一行的对象,所以当从 TDataSet 中添加或删除记录时,我需要得到通知。我就是不知道该怎么做。
显然,我不想挂钩数据集事件;它们可能已经在使用中,并且 TDataLink 旨在成为我的控件和数据集之间的中介。我尝试使用 DataEvent 虚拟方法失败了,因为它根本不告诉您是否正在添加/删除记录。
有什么想法吗?
I am writing a grid control that will display the contents of either a TDataSet or a TObjectList. When you only need to support TDataSet, things are quite simple:
- Link to the dataset via a TDataLink descendant.
- When painting the contents of the grid, you can use the records buffered in that TDataLink to paint what you need to.
- There is no need to have individual objects somewhere to represent rows in the TDataSet, because you always just paint the rows in the buffer.
In my case, I need to accept data from a few other sources as well, which meant that I needed to have an object representing each row (also because the control required quite a bit of row state).
But this causes problems with the model described above. Because I have an object representing each row, I need to be informed when records are added or deleted from the TDataSet. And I just cannot see how to do that.
Clearly, I don't want to be hooking to the dataset events; they may already be in use and the TDataLink is meant to be the mediator between my control and the dataset. And my attempts at using the DataEvent virtual method failed, because it simply doesn't tell you if a record is being added/deleted.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果将 TDataLink 后代挂钩到连接到 TDataSet 的 TDataSource,则当数据更改时,您将在 RecordChanged 过程中得到调用。
您可以使用连接到 TDataSet 的 TDataSource 的事件 OnDataChange 和 OnUpdateData。
If you hook your TDataLink descendant to a TDataSource that is connected to the TDataSet you get a call in the RecordChanged procedure when data changes.
You can use the events OnDataChange and OnUpdateData of a TDataSource connected to the TDataSet.
看来,您必须从要使用的基本数据集类派生您自己的类。在那里,您将需要重写InternalAddRecord、InternalPost、InternalDelete方法并处理记录添加/删除。
It seems, you have to derive your own class from the base dataset class you are going to use. There you will need override InternalAddRecord, InternalPost, InternalDelete methods and handle records addition / deletion.