1

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??

Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
Jur
  • 520
  • 2
  • 18
  • He says he "found" the starke record and jumped to it; but my search string was "ad" which doesn't occure in "Starke" – Jur Aug 26 '20 at 09:29
  • 2
    Does https://stackoverflow.com/a/28232896/2292722 provide an answer? – Tom Brunberg Aug 26 '20 at 10:31
  • Well, it surely provides a pointer... thanks, Tom. Kinda weird to leave a bug like this in a standard and popular function for over 15 years though?? – Jur Aug 26 '20 at 10:43
  • Yup, that's exactly the problem; in the unfiltered dataset there's a "Adriaan" right above "Starke". Don't know yet how I'm going to solve it, I'm a bit hesitant to implement my own LOCATE function or mess in Delphi source code, so I may include the filter in the SQL's WHERE as well. – Jur Aug 26 '20 at 10:55
  • *working as designed and documented* is not a bug. – Ken White Aug 26 '20 at 18:35
  • a bug may be documented, surely. And I can't believe anyone DESIGNED it like this. – Jur Aug 28 '20 at 15:37

0 Answers0