How to get FireDAC record count when SetRange active

3.6k Views Asked by At

I'm slowly moving from ClientDataSet to FireDAC FDQuery components in my projects (Delphi 10 Seattle).

One trick I often use with CDS is to check record count on a range.

That is:

CDS.SetRange([Value1][Value2]);  
k := CDS.RecordCount;  
case k of  
  1 : DoSingleThing;  
  2 : DoDoubleThing;  
else  
  BailOnWrongCount;  
end;  

Because I need the entire set of data available at the same time, I use FetchOptions.Mode := fmAll when first opening the query.

Doing FDQuery.SetRange([Value1][Value2]); then calling FDQuery.RecordCount always returns the record count of the entire dataset (as per fmAll) - not the current range.

I'm having to loop through the range counting records manually.

Is there a simpler way to get the number of records in the current range?

1

There are 1 best solutions below

3
da-soft On BEST ANSWER