AdvStringGrid: Difference between "RemoveSelectedRows()" and "RemoveRows()" with Hidden rows/columns?

Hallo!

We have a grid with hidden rows and columns and "disjunctrowselect = true". Now we want to remove the selected rows.

  1. With RemoveRows():
    MyGrid.BeginUpdate;
    for i := 0 to MyList.Count - 1 do
    begin
      RowIndex := GetRowIndex(MyList[i]);
      MyGrid.RemoveRows(RowIndex, 1);
    end;
   MyGrid.EndUpdate;

It removes them correctly, but has really bad performance, because it removes row by row and redraws the Grid every time.

  1. With RemoveSelectedRows():
   MyGrid.BeginUpdate;
   MyGrid.RemoveSelectedRows;
   MyGrid.EndUpdate;

It removes them instantly without performance issues. But now if we close our application, which frees the grid, we get an invalid pointer exception here:

procedure TBaseGrid.SetCellProperties(c, r: integer; const Value: TCellProperties);
begin
  if Assigned(inherited Objects[c,r]) then
      TCellProperties(inherited Objects[c,r]).Free;

  inherited Objects[c,r] := Value   <---- Invalid Pointer here!
end;

Any idea why? In this topic ( Memory leak on TAdvStringGrid - #7 by Duffy_David ) it seems, that it can be necessary to "clearrows" because of this.

Thanks

Are you using cell properties to begin with? If you use cell properties, you might try to clear these rows first before removing with grid.ClearRows()

Removing rows one by one is a bad idea. It requires row re-arranging for every single call to remove a row.
You can also remove multiple rows at once with the grid.RemoveRowList() method.

Thanks for the fast reply.
For some context:
We use cellproperties to colorize our rows gray(rowfontcolor). In this special case all gray rows, which fulfill a certain condition, are hidden. If I unhide all those row and then delete a row it works. If I hide all gray rows and then delete a row it doesnt work (=if I destroy my form I get the exception in the TBaseGrid-function).

ClearRows() also didnt help (with MyGrid.ClearRows(1, MyGrid.AllRowCount-1)).
Is there a way to clear all cellproperties maybe?