SelectWordAt in a Cell

General TRichView support forum. Please post your questions here
Post Reply
VoodooMike
Posts: 5
Joined: Sun Jan 15, 2006 9:50 am
Contact:

SelectWordAt in a Cell

Post by VoodooMike »

I've recently started converting my chat application over to using tables for displaying messages, and I've noticed something strange in regards to using SelectTextAt. Doing a SelectTextAt on a word early on in a chat session can cause an index out of bounds exception if there aren't enough lines (tables) in the document yet.

For example, if I do a SelectWordAt on the third item in a table that makes up the first line of a document, it will give an index out of bounds error on item 3. If I wait until there are three lines, then it won't... and it'll highlight the word properly.

I'm using the selectwordat function off the primary document - so there isn't a 3rd item in it at first, because the first item is the table that contains the word... but if there IS a third line, then highlighting works properly.

What should I do?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Can you send me a simple project reproducing this problem?
VoodooMike
Posts: 5
Joined: Sun Jan 15, 2006 9:50 am
Contact:

Post by VoodooMike »

Just put a normal TRichView on a form, with a TRVStyle linked to it, and use the following:

Code: Select all

procedure TForm1.RichView1RVMouseDown(Sender: TCustomRichView;
  Button: TMouseButton; Shift: TShiftState; ItemNo, X, Y: Integer);
begin
  Richview1.SelectWordAt(x,y);
end;

procedure TForm1.FormShow(Sender: TObject);
var table:TRVTableItemInfo;
    i:integer;
begin
  table:=TRVTableItemInfo.CreateEx(1,3,RichView1.RVData);
  table.Cells[0,0].AddNL('Column 1',0,0);
  table.Cells[0,1].AddNL('Column 2',0,0);
  table.Cells[0,2].AddNL('Column 3',0,0);
  richview1.AddItem('Table',table);
  richview1.format;
end;
Then click on the first word... if you loop through that and have it place three tables, then there's no problem and it should select the word properly.
Post Reply