I'm trying to search a TDBF dataset using Filter, and checking for results using Found. I'm having trouble getting Filter to work.
EX:
TDBF.Filtered := False;
TDBF.Filter := 'FieldName=intValue'; -or- TDBF.Filter := 'FieldName="strValue"';
TDBF.Filtered := True;
//Now check to see if we have results
If TDBF.Found then // some code here
-or
If TDBF.FindFirst then // some code here
-or-
TDBF.First;
If Not TDBF.EOF then // some code here
TDBF.Found and TDBF.FindFirst return false. TDBF.EOF returns what I would expect, but the dataset is not filtered.
Also the comparison operators and be either <, <=, >=, > as well. I also have
OnFilterRecord event returning Accept := True. I know I'm not doing something right. The dataset seems to be acting as if I did not apply a filter.
Could some one be good enough to iterate or offer suggestions? I hope this post makes sense to somebody. Thanks for reading.
Heres my code.
// Function Find.
// Locates first occurance in a record based on
// information supplied. And returns whether or
// not the dataset was able to able to locate the
// information.
//
// Parameters:
// V : String
// The value to be searched for.
// CS : String
// Compare String. Used to build filter string
// to supplied to Field.dataset.filter property.
// F : TField.
// Field to be used compare with.
//
// Variables:
// DS : TDBF
// Dataset derived from the field passed to this
// function.
// N : String
// Name of the field derived from the field
// passed to this function
Function TDM.Find(V, CS : String; F : TField) : Boolean;
var
//DS^ : TDataSet;
N : String;
ft : TFieldType;
Begin
//DS := F.^DataSet;
N := F.FieldName;
ft := F.DataType;
with (TDBF(F.DataSet)) do
begin
Filtered := False;
if ft = ftString then
Filter := N + CS + '"' + V + '"'
else
Filter := N + CS + V;
Filtered := True;
Refresh;
// If Found then
// begin
// check first char in CS to determine direction of search.
if POS('<', CS) > 0 then
begin
Result := FindLast;
// Result := Found;
// Result := not BOF;
end
else
begin
Result := FindFirst;
// Result := Found;
// Result := not EOF;
end;
//end
//else
// Result := False;
end;
End;