Locate jumping to wrong record

179 views Asked by At

I have the weirdest of problems: a Dataset.Locate which SAYS he found a record and jumps to it, BUT the record doesn't fit the criteria.

Here's my code:

procedure TFZoekEmp.edtZoekNaamEmpChange(Sender: TObject);
var
  lFound:boolean;
begin
  lFound:=FDataSet.Locate('EMNM', edtZoekNaamEmp.Text, [loCaseInsensitive, loPartialKey]);
  if lFound then
    WWMessageDlg('Looking for:'+edtZoekNaamEmp.Text+'/found:'+ FDataset.fieldbyname('EMNM').asstring,mtWarning,[mbOK],0)
  else
    WWMessageDlg('Looking for:'+edtZoekNaamEmp.Text+'/but alas, not found.',mtWarning,[mbOK],0);
end;

and here's a screen shot of the output:

enter image description here

It is a simple procedure for entering an employee name in an overlay ("Zoek employee" window in screen shot) and jumping to the first record which contains the search string (the grid on the main form, on the left)

I'm using Delphi 10.3. FDataset is a TADODataset which connects to a local Access database, fed by a dynamically created SQL string. Aside from a WHER in that SQL statement, the dataset is further filtered by the "Filter" attribute of the dataset.

There is an option to change the sort order of the grid. When it is actually sorted by name (ORDER BY clause), everything works fine; when it is sorted on date of birth the above results occur.

Can I not trust the "locate" procedure of TDataset anymore??

0

There are 0 answers