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?
Set FetchOptions.RecordCountMode to cmVisible: http://docwiki.embarcadero.com/Libraries/Seattle/en/FireDAC.Stan.Option.TFDFetchOptions.RecordCountMode