0

I need help with the following problem. I have a dbgrid, the underlying query is filtered. I want to apply a new filter but stay at the same row number in the dbgrid. Here is my code:

with qrProperties do
begin
  ...
  MyPoint:=GetBookmark;
  Filter:='N<>'+IntToStr(ResultPropertyN);
  Filtered:=True;
  GotoBookmark(MyPoint);
end;

When it gets executed, an EDBEngineError is raised with a message "Could not find record". My explanation is that the bookmark functions do not take into account the filter and the procedure GotoBookmark searches for a record that is not present in the dbgrid (due to the filter applied). Is there any way to use bookmarks with filters?

Here are a little more details. In my application when I double click on a row in the dbgrid, it disappears (due to the filter applied) but as a result of the filtering the cursor moves to the first row (if I do not use bookmarks). I want it to stay at the same row number that is to go to the record shown immediately after the one that has been deleted.

Rick77
  • 241
  • 3
  • 21
  • What kind of behavior would you expect if GotoBookmark is not able to locate a record, since it is a procedure not a function? – bummi May 07 '13 at 08:24

1 Answers1

1

Your assumption is correct, the record is no longer 'there'.

Wrap GotoBookmark in a try/except and decide what to do in the exception, e.g. go to the first record.

Alternatively you could go to the 'nearest' record you can find. That depends on what you consider 'nearest' and then you would not need bookmarks at all and use e.g. FindNearest.

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144