开发者

How do I determine when a record is inserted in a TDataSet?

开发者 https://www.devze.com 2023-02-03 19:17 出处:网络
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:

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:

  1. Link to the dataset via a TDataLink descendant.
  2. When painting the contents of the grid, you can use the records buffered in that TDataLink to paint what you need to.
  3. There is no need to have individual objects开发者_StackOverflow社区 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消