Pregunta

My C++ CAD application maintains logs of the user's modeling operations so that they can be unapplied and reapplied. Any particular project may contain just a few operations or it may contain hundreds of thousands of operations. I already have my own data structures in place to manage this data in a way that is memory-efficient, and this has been working well. But now I am adding a feature that allows the user to inspect his operation logs in a grid. (I am using Embarcadero RAD Studio 2010; all GUIs use VCL.)

Currently, I am using a TDBGrid component to show the user the operation data in rows. Here is how I have my components connected up:

TDBGrid.DataSource = a TDataSource

TDataSource.DataSet = a TClientDataSet

TClientDataSet.ProviderName = a TDataSetProvider

TDataSetProvider.DataSet = a ProjectDataSet

A ProjectDataSet is a class I derived from TDataSet.

Because I am pulling the operation data from my own data structures and not from a database, I have overridden the GetFieldData and GetRecord functions (and several others) in my ProjectDataSet class so that it returns the data directly from my own data structures (without doing any database queries). This works.

In order to minimize memory usage when displaying lots of operations, I have set the 'FetchOnDemand' property in my TClientDataSet and I have set 'PacketRecords' to 100. So, initially only the first 100 operations appear in the grid. Once the user scrolls to the bottom of the grid, the next 100 operations are automatically fetched by the TClientDataSet and displayed in the grid.

All of this works very well. My problem is that as the user scrolls through the grid, the TClientDataSet keeps on fetching more and more records without ever releasing any. So, if the user scrolls down far enough in a very large project, I eventually run out of memory.

So, my question is: what is the best way to make this GUI work? Essentially, I want the grid to behave like a spreadsheet. I want the user to be able to scroll up and down through the operation list (or jump to a specific row), regardless of how many operations there are, and I don't want the GUI components keeping a lot of stuff in memory that the user doesn't imminently need.

I'm assuming that the TDBGrid (or some other VCL component) is designed to be capable of displaying arbitrarily large datasets by fetching only a few records at a time, so how is it meant to be done?

If I need to rethink the GUI, that's fine. But it would be really nice if I could use the same GUI to display 10-operation projects or 100,000-operation projects.

Thanks.

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top