FlexCel Studio for VCL/LCL
ContentsIndex
PreviousUpNext
TFlexCelReport.CalcRecordCount Property

Method FlexCel will use to calculate the record count of a DataSet.

Pascal
property CalcRecordCount: TCalcRecordCount;
C++
__property TCalcRecordCount CalcRecordCount;

If you have spent some time with different databases, you probably are aware of all the issues regarding TDataSet.RecordCount. 

Some databases return the right number of records, others will give the unfiltered count (be careful with these, they may work right until someone filters the dataset), others will give always -1, and in short, every data layer seems to like returning his own number on this property. 

 

The conclusion to it would be "don't use RecordCount at all". But we really needed to. Inserting rows in Excel is by far the most time consuming task, much more than counting the records. So the code: 

 

db.First;
Rc:=0;
while not db.eof do inc (Rc);
ExcelApp.InsertRow(Rc) ;

 

is normally much faster than: 

 

db.First;
while not db.eof do ExcelApp.InsertRow

 

So, depending of the database and the dataset you use, there are 4 ways to count the records: The first is using the OnRecordCount event, and the others are setting CalcRecordCount to: 

 

Value 
Meaning 
cr_None 
Use it if you are sure RecordCount is always right, with the dataset filtered or not. This is the case if you are using a TClientDataSet. You can safely use this mode with ClientDataSet or TFlxMemTable databases. 
cr_Count 
The default. It will make a db.Last before using RecordCount, to make sure all records have been fetched. This works with some BDE datasets, or InterbaseExpress. 
cr_SlowCount 
This will assume RecordCount is always wrong and count the records one by one using a procedure like the one in the example above. Whenever you are not sure, or you are getting strange results use this mode. 
Copyright (c) 2002-2008 TMS Software. All rights reserved.
What do you think about this topic? Send feedback!