[Lazarus] How TDBGrid works

Jesus Reyes A. jesusrmx at gmail.com
Fri May 6 07:19:44 CEST 2016


En Thu, 05 May 2016 16:53:00 -0500, Aradeonas <aradeonas at operamail.com>  
escribió:

> Hi,
>I'm curious about how TDBGrid now what to show in a column as value.
> I mean if I want to make a custom grid simple solution si going from  
> first to last of TDataset and read columns value.
> I Browsed TDBGrid code lately but sadly I couldnt find how it works to  
> get data without (as I think) browsing and changing TDataset records.
>Regards,
> Ara
>--http://www.fastmail.com - Send your email first class

DBGrid does not read all records from first to last in order to show them,  
it only "specify" how many records it can show at the same time, it does  
this using a data link, TComponentDatalink, which is just a TDatalink with  
some custom dataset events for easy hooking, a data link is an  
intermediary between the grid and the dataset. So once the amount of  
records is set, the grid uses a datalink property: ActiveRecord in order  
to select which record from the ones it has reserved is the active record,  
then DbGrid maps this active record to the grid.Row property, the grid.Col  
property is mapped to a field index and using the standard dataset  
properties like Fields[i] or the field associated to a column which is  
again just taken from the dataset.

The dataset is in charge all the time in keeping the reserved records up  
to date, the grid just shows the values it finds in the records.

The starting point when the records are shown in DbGrid is procedure  
TCustomDBGrid.DrawAllRows; there the ActiveRecord is selected, DrawAllRows  
eventually ends calling  individual cells for each row which does  
DefaultDrawCell and several others.

In bug report http://bugs.freepascal.org/view.php?id=29764 I put an  
example of using TDatalink with multiple records and without DbGrid in a  
console program. Hope that helps.

Jesus Reyes A.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160506/8c790a0e/attachment-0003.html>


More information about the Lazarus mailing list