[lazarus] TDBGrid question

Michael Van Canneyt michael.vancanneyt at wisa.be
Fri May 23 16:10:20 EDT 2003




On Fri, 23 May 2003, [iso-8859-1] Jesus Reyes wrote:

>  --- Michael Van Canneyt <michael.vancanneyt at wisa.be> escribió: >
> >
> > On Fri, 23 May 2003 hernan.et at pg.com wrote:
> >
> > > Hi Jesus,
> > >
> > > The scrollbars work for me now just fine. Here is what I did.
> > >
> > > I created another TIBQuery, this will just tell me how many
> > records are returned
> > > based on the SQL passed.  I don't understand why I can't get the
> > number of
> > > records when using pure sql, e.g.
> > >
> > > myIBQry.SQL.Clear;
> > > myIBQry.SQL.Add('Select * from items');
> > > myIBQry.Open;
> > > myIBQry.RecordCount does not work (myIBQuery is of type
> > TIBQuery).
> >
> > The only way to get the number of records returned by a query,
> > is to scroll to the last record. IB does not return the number of
> > records in a result set.
> >
> > >
> > > my second query looks like this
> > >
> > > myIBSecond.SQL.Clear;
> > > myIBSecond.SQL.Add('Select count(ID) as NumOfItems from items');
> > > myIBSecond.Open;
> > >
> > > myTDBGrid.RowCount := IntToStr(myIBSecond.Fields[0].AsString);
> > //note no
> > > AsInteger I don't know why
> > > myTDBGrid.BufferCount :=  myTDBGrid.RowCount; //this will update
> >
> > This is VERY bad, it will allocate a HUGE amount of memory when
> > your query returns a lot of things.
> >
> > The buffercount of the grid (and dataset) should equal the number
> > of
> > rows that are displayed on the screen.
> >
> > Michael.
> >
>
> In fact this is the problem that I have with the scrollbars, the
> default scrollbar handling depends of the grid's total width/height
> and that depends on rowcount/colcount, by setting this properties
> directly you are allowing the default scrollbar handling and
> scrollbars works normally, however as Michael wrote this is not
> recommended {well actually, I think in some cases a buffered rowset
> its s wellcome feature :)} Currently dbgrids only request a number of
> buffers that are visually needed.

This is the correct behaviour. If you look at a DBGrid in Delphi, you
will notice that it's scrollbar doesn't work 'normal'; it only supports
paging forward and backward, the position of the thumb is usually in the
middle of the grid; exactly because the grid doesn't know how many rows
there actually are.


>
> I only tested IB components with very small dataset rows so i did't
> know if there were problems scrolling, in this matter, I think, one
> should play with the dataset scrolling rules if the underlaying
> dbengine allows backward/forward scrolling then any grid's request
> should succed. Should one trust FDataLink.DataSet.RecordCount for
> something? I need investigate further :) .

The 'recordcount' should under no circumstance be trusted. It may change
as you navigate through the records. Check out IBDAtaset from IBX: the
recordcoount is initially 1, and is updated as you scroll through the
dataset. To get the correct recordcount, one must do a 'last', obtain
the recordcount, and then do a 'first' again. This possibly will fetch
all data _twice_ so it is not recommended.

On the other hand, MySQL does return a correct recordcount which can be
used even without navigating through all records.

Michael.






More information about the Lazarus mailing list