[Lazarus] Proper implementation of TDataLink descendant
Michael Van Canneyt
michael at freepascal.org
Thu Aug 4 18:34:23 CEST 2011
On Fri, 5 Aug 2011, Alexander Klenin wrote:
> After researching http://bugs.freepascal.org/view.php?id=19887, I have
> found the following:
>
> 0) For context, here is TDbChartSource desctiption:
> http://wiki.lazarus.freepascal.org/TAChart_documentation#Database_source
> 1) My implementation of TDbСhartSource is incorrect, because during
> the chart drawing
> it accesses dataset directly from the TDataLink descendant.
> Apparently this causes infinite loop, because such accesses generate
> DataSetChanged events,
> which in turn invalidate the chart.
> Even DisableControls/EnableControls do not help, since
> EnableControls calls DataSetChanged (!).
> 2) Looking at the code in TDBGrid, it seems that the correct way is to
> use DataLink's ActiveRecord property.
> Unfortunately, in contrast to TDBGrid, TDbСhartSource needs to read
> the whole dataset.
> It seems that the only way to do this is to set BufferCount :=
> RecordCount, i.e. buffer entire dataset in memory,
> which I do not like.
>
> So, my questions are:
>
> 1) Is there a way to totally disable DataSetChanged events in the dataset?
No.
You only disable the treatment of the event while browsing.
Something like
If not Floading then
LoadChart;
Procedure LoadChart;
begin
Floading:=True;
try
// Browse data and build series.
finally
Floading:=False;
end;
end;
> 2) Alternatively, is there a mechanism to read entire dataset via
> TDataLink without fully buffering it?
No, for obvious reasons. I think that for the tchart, you should not bother with the
buffer mechanism. Just do a
First;
While not EOF do
begin
AddPointToSeries;
Next;
end;
A chart always sees the dataset as a whole. DB aware controls normally see only 1 record.
Normally, a grid sees as much records as it currently displays rows.
But many advanced grids also browse the whole dataset when building rows;
they don't bother with Activebuffer and buffercount. (
Michael.
More information about the Lazarus
mailing list