I get wrong recordcount after TBufDataSet or TSQLQuery is filtered, what should I do?
so write a function as follow:
function getRecordCount(cds:TDataSet):integer;
var
myfield:TField;
sFName,sVal,sE:String;
begin
try
result := 0;
if cds = nil then
result := -1;
if cds.Active = false then
result := -2;
if result < 0 then
exit;
result := cds.RecordCount;
if result = 0 then
exit;
myfield := nil;
sVal := '';
with cds do
begin
sFName := 'M001';
myfield := Findfield(sFName);
if myfield <> nil then
begin
sVal := FieldByName(sFName).AsString;
end;
myfield := nil;
if sVal = '' then
begin
sFName := 'D001';
myfield := Findfield(sFName);
if myfield <> nil then
begin
sVal := FieldByName(sFName).AsString;
end;
end;
if sVal = '' then
begin
sFName := 'FBRNO';
myfield := Findfield(sFName);
if myfield <> nil then
begin
sVal := FieldByName(sFName).AsString;
end;
end;
if sVal <> '' then
result := 1
else
begin
result := 0;
exit;
end;
Next;
if eof then
result := 1
else
begin
result := 2;
Prior;
end;
end;
except
on E:Exception do
begin
sE := E.Message;
try
SaveTextToDisk(DefaultPath+'log\'+formatdatetime('yymmddhhmmss',
now) + '_getRecordCount.txt','; error:'+sE);
except
end;
end;
end;
end;