[Lazarus] db grid/dataset components that only load currently visible records?

Michael Van Canneyt michael at freepascal.org
Thu Feb 23 11:11:55 CET 2023

On Thu, 23 Feb 2023, Luca Olivetti via lazarus wrote:

> El 23/2/23 a les 9:43, Michael Van Canneyt via lazarus ha escrit:
>>> Something like this:
> https://docwiki.embarcadero.com/RADStudio/Rio/en/Browsing_Tables_(FireDAC)#Live_Data_Window_Mode
>> This is not something that the grid handles. This is a dataset feature.
> Yes, I supposed so
>> At this moment I know of no FPC/Lazarus dataset component that handles 
>> this automatically.
> bummer :-(
>> Note the remark on that page:
>> "Although FireDAC minimizes the number of generated and executed SQL 
>> commands in LDW mode,
>>   it still produces a heavier DB load than TFDQuery. So, application 
>> developers should
>>   carefully choose when to use TFDTable and LDW mode. "
>> This is exactly why FPC does not have a database table component. It's 
>> horribly inefficient.
> OTOH a TDBGrid is a very convenient way to display data.
> I my application I just use it to display (in read-only mode) an sqlite 
> table that holds less than 1000 records and it could be updated quite 
> frequently (hence the need for the frequent TDataset.refresh), and it 
> works fast enough with that limited amount of records.
> Now I need to expand the table to 10000 records and the performance is 
> unacceptable.

The best way is to use "limit N offset M" in your query and use a paging
mechanism. Make sure you sort the records, obviously.

But IMO: 
in the first place you should ask yourself if displaying 10.000 records is
what you actually want to do.

Maybe your application is better off with some filtering ?


More information about the lazarus mailing list