Question

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 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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top