Tranverse and update selected rows

In our old (but still working) TopGrid3 we were able to specify BookmarkType as bmtNonOrdered for our Advantage database 9.1 that does not have ordered records. With that we were were able to walk through their SelectedRows list that links next selected bookmarks and update a field (Status) in those selected rows:

Var
  Bkm: Variant;
begin
  with  tsDBGrid1 do
    begin
       BookmarkType := bmtNonOrdered;  // !! MUST do this, else will only change the first selected record
       Bkm := SelectedRows.First;
       while not VarIsEmpty(Bkm) and not FCancelRequested do
       begin
            AdsQuery1.Bookmark := Bkm;
            LabelStatus.Caption := 'Changing status to ' + NewStatus + ' for record ' + IntToStr(AdsQuery1.Recno);
            Application.ProcessMessages;
            AdsQuery1.Edit;
            AdsQuery1.FieldByName('status').AsString := NewStatus;
            AdsQuery1.Post;
            Bkm := SelectedRows.Next(Bkm);
       end;
    end;
end

Above works just fine with TopGrid3 selected disjunct rows..

We have tried to re-implement this essential functionality in TMS relying on TMS  RowSelect flags collection, instead of TopGrids's linked list.

With TMS we use:
  PageMode = True
  DataSetType=dtNonSequenced
  DatasetTypeAuto=True
  DataSource.AutoEdit=True
  MouseAction.RowSelect=True
  MouseAction.DisjunctRowSelect=True
  EditPostMode=epCell
  FolterActive=False
  Navigation.SelectAll=True
  Options.goRowMoving=false
  Options.goEditing=True
  ScrollSynch=False

Having tried GetBookmark and GotoBookmark and MoveBy from TDataSet/TAdsQuery descendant to transverse selected row,  we run into the same problem - it has worked only for the first selected give and take it was moved to  the bottom. The consequent selected rows are not moved, even though the MoveBy index was correct in the debugger. We use Delphi 2007 Win32. Our non-advancing to the second bookmark TDBAdvGrid code is below:

 AdsQuery1.UpdateCursorPos;
 bkm := AdsQuery1.GetBookmark;
 AdsQuery1.DisableControls;
 try
    AdsQuery1.Refresh;
   with tmsDBGrid1 do
      begin
        j:= 0;
        AdsQuery1.First;
        CursorWait;
        for RowIndex := 1 to tmsDBGrid1.RowCount -1 do
        begin
          if tmsDBGrid1.RowSelect[RowIndex] and not FCancelRequested then
          begin
            if SelectedRowsCount > 0 then
            begin
              result := AdsQuery1.MoveBy(RowIndex - 1 - j);
              LabelStatus.Caption := 'Changing status to ' + NewStatus + ' for record ' + IntToStr(AdsQuery1.Recno);
              Application.ProcessMessages;
              AdsQuery1.Edit;
              AdsQuery1.FieldByName('status').AsString := NewStatus;
              AdsQuery1.Post;
              AdsQuery1.GotoBookMark(bkm);
              j := RowIndex - 1;
              Dec(SelectedRowsCount);
            end
            else
              Errmsg('(Program Error: More rows processed than selected)', pause);
          end;
        end;
      end;
    finally
      LabelStatus.Caption := '';
      AdsQuery1.FreeBookmark(bkm);
      AdsQuery1.EnableControls;
      CursorRestore;
      tmsDBGrid1.ClearSelection;
      FCancelRequested := false;
      ButtonCancel.Enabled := false;
    end;

Could you please help us with an example how to get to second and consequent selected rows/records to modify them to be viewed updated in place on the screen with DBAdvGrid with  unordered TDataSet descendant (TAdvQuery) record numbers?

To use this specific functionality to loop through selected rows, it will be required to set grid.PageMode = false. When PageMode = true, only visible records are present and thus only state of visible records can be maintained. 

Can you recommend a way to traverse and update field(s) in selected rows under PageMode=true, with that PageMode=True limitation - selected only when visible by CTRL MouseClicking on them? With or without scrolling permitted?


Alternatively, what are the implications of changing PageMode to false programmatically and back to True, to implement this particular functionality.

You'd need to maintain at application level a list of bookmarks of selected rows and implement the OnGetCellColor event to mark rows that are in the bookmark list in a different selected color.
Then loop your list of bookmarks to perform an action on it.