Search code examples
delphidelphi-5

Addition and subtraction with TBookmark object


My question is how I can do operations like addition and subtraction with TBookmark object. For example, let's say I want to go 4 rows higher in the dbgrid:

MyPoint:=Query1.GetBookmark;
...
//MyPoint:=MyPoint-4;
Query1.GotoBookmark(MyPoint);

Here the commented line is wrong. It produces a "Operator not applicable to this operand type" message. The question is what I should write in place of the commented line. Thanks in advance!


Solution

  • You cannot perform arithmetic directly on a bookmark. To do what you ask you need to go to the bookmark, and then move relative to that:

    Query1.GotoBookmark(MyPoint);
    Query1.MoveBy(-4);
    

    If you wish, you could then save another bookmark representing that record.