Page 1 of 1

List Bounds exception when accesing table cells

Posted: Sun Nov 19, 2006 6:32 pm
by mamouri
Here is a code that I use in my project for highlighting the cell that is mouse is over it:

Code: Select all

procedure TfStory.RVMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  P: TPoint;
  Row, Col: Integer;
  I, J: Integer;
begin
  for I := 0 to ATable.Rows.Count do
    for J := 0 to ATable.Rows[I].Count - 1 do
      if ATable.Cells[I, J] <> Nil then
        ATable.Cells[I, J].Color := clWhite;


  P := RV.ScreenToClient(Mouse.CursorPos);
  ATable.GetCellAt(P.X, P.Y, Row, Col);
  ATable.Cells[Row, Col].Color := clRed;
end;
I have two question:
1- Does such use of RVMouseMove is correct? I considered that it dosen't work if user move the mouse over an empty area in cell.

2- It raise an List Bounds exception in following line:

Code: Select all

        ATable.Cells[I, J].Color := clWhite;
I checked before this line does cell is exist or not (because some of cells in table are merged)

Thank you

Posted: Sun Nov 19, 2006 6:48 pm
by Sergey Tkachenko
As for the error, change
for I := 0 to ATable.Rows.Count do
to
for I := 0 to ATable.Rows.Count-1 do

As for determining the cell under mouse, it's wrong.
X and Y parameters for table.GetCellAt must be relative to the top left corner of the table (client coordinates are relative to the top left corner of trichview window).

Assuming that ATable is inserted directly in RV (it is not a nested table), you can use this code:

Code: Select all

var TableX, TableY: Integer;
...
RV.GetItemClientCoords(ATable.GetMyItemNo, TableX, TableY);
if ATable.GetCellAt(X-TableX, Y-TableY, Row, Col) then
  ATable.Cells[Row, Col].Color := clRed; 

Posted: Sun Nov 19, 2006 7:26 pm
by mamouri
Thank you very much. It work fine. another question. How refresh or repaint Richview flicker free? I used Refresh, Update, Invalidate method but all of them flicker all richview.

Posted: Sun Nov 19, 2006 7:40 pm
by Sergey Tkachenko
It's strange, TRichView must not flicker on repainting.

Posted: Sun Nov 19, 2006 7:55 pm
by mamouri
Maybe because I added some control into RichView.
Does it flicker if we have some controls added to RichView?

Posted: Sun Nov 19, 2006 8:30 pm
by Sergey Tkachenko
What types of controls?

Posted: Sun Nov 19, 2006 8:33 pm
by mamouri
TRzToolbarButton
It work like TSpeedButton.

Posted: Sun Nov 19, 2006 9:49 pm
by Sergey Tkachenko
Is it inherited from TWinControl, or from TGraphicControl?
I guess from TGraphicControl, otherwise rv.Invalidate does not repaint it.
I am afraid it is this control what flickers, not TRichView... May be it has property like Transparent or Opaque? May be, in non-transparent mode, it will not flicker.

Posted: Mon Nov 20, 2006 11:41 am
by mamouri
You're correct. It's inherited from TGraphicControl. In fact this control was flickering and I was thought that all richview is flickering.
I changed the control and problem solved.