List Bounds exception when accesing table cells

General TRichView support forum. Please post your questions here
Post Reply
mamouri
Posts: 63
Joined: Sat Aug 19, 2006 5:06 am

List Bounds exception when accesing table cells

Post 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
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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; 
mamouri
Posts: 63
Joined: Sat Aug 19, 2006 5:06 am

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It's strange, TRichView must not flicker on repainting.
mamouri
Posts: 63
Joined: Sat Aug 19, 2006 5:06 am

Post by mamouri »

Maybe because I added some control into RichView.
Does it flicker if we have some controls added to RichView?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

What types of controls?
mamouri
Posts: 63
Joined: Sat Aug 19, 2006 5:06 am

Post by mamouri »

TRzToolbarButton
It work like TSpeedButton.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
mamouri
Posts: 63
Joined: Sat Aug 19, 2006 5:06 am

Post 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.
Post Reply