List out of bounds Exception in TRVEditRVData.GetCurItemNo

General TRichView support forum. Please post your questions here
Post Reply
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

List out of bounds Exception in TRVEditRVData.GetCurItemNo

Post by Michael Pro »

Sergey, I've got one nasty bug - sometimes while drag'n'drop selected text I've got this exception.
I'm calling actions update on OnCaretMove event - and inside it I'm calling this function.
I'm making drag'n'drop in tables - and sometimes this bug happens.
Any ideas about that?

Michael.
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

Post by Michael Pro »

Well, I think, that document in this case simply unformated - but why this happens, I couldn't say.

I made some modifications - don't know, am I right...

Code: Select all

function TRVEditRVData.GetCurItemNo: Integer;
  {........................................}
  function IndexOf(obj: TObject): Integer;
  begin
    if not Assigned(DrawItems) then
    begin
      Result := -1;
      Exit;
    end;
    if CaretDrawItemNo > DrawItems.Count - 1 then
    begin
      Result := -1;
      Exit;
    end;
    if DrawItems[CaretDrawItemNo].ItemNo > Items.Count - 1 then
    begin
      Result := -1;
      Exit;
    end;
    if (CaretDrawItemNo>=0) and (Items.Objects[DrawItems[CaretDrawItemNo].ItemNo]=obj) then
      Result := DrawItems[CaretDrawItemNo].ItemNo
    else
      Result := Items.IndexOfObject(obj);
  end;
  {........................................}
begin
  PrepareForEdit;
  if FPartialSelectedItem<>nil then
    Result := IndexOf(FPartialSelectedItem)
  else if GetChosenItem<>nil then
    Result := IndexOf(GetChosenItem)
  else if CaretDrawItemNo=-1 then
    Result := -1
  else
  begin
    if CaretDrawItemNo <= DrawItems.Count - 1 then
      Result := DrawItems[CaretDrawItemNo].ItemNo
    else
      Result := -1;
  end;
end;
Sergey Tkachenko
Site Admin
Posts: 17499
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

OnCaretMove may be called when the document is not formatted yet.
Selection-related methods must not be used in this event, but methods related to the caret position must be available.

Do you use RichView 10.0? It looks like all checks for the range of CaretDrawItemNo are already implemented.
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

Post by Michael Pro »

Sergey Tkachenko wrote:Do you use RichView 10.0? It looks like all checks for the range of CaretDrawItemNo are already implemented.
Actually, no. We've bought 1.9 version on 3rd of March in 2006.
Maybe I could use OnAfterCaretMove event to make changes on my actions?
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

Post by Michael Pro »

Or maybe it's simplier to check rvstEditorUnformatted flag in editor state before actions updating?
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

Post by Michael Pro »

Not sure, but with this code my actions started worked fine

Code: Select all

  if (rvstEditorUnformatted in RvData.State) or (rvstMakingSelection in RvData.State)
    or (rvstDeselecting in RvData.State) or (rvstStartingDragDrop in RvData.State) or
    (rvstForceStyleChangeEvent in RvData.State) or (rvstLineSelection in RvData.State)
    or (rvstClearing in RvData.State) then
    Exit;
Sergey, could this part solve my troubles for updating?

Best regards,
Michael.
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

Post by Michael Pro »

Won't help (((
Sometimes RVData is in rvstForceStyleChangeEvent state - and it won't help ((((
Sergey Tkachenko
Site Admin
Posts: 17499
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

These flags are for internal use and do not necessary mean that you expect.
You can upgrade to version 10.0, it's free.
Michael Pro
Posts: 42
Joined: Wed Feb 28, 2007 4:14 am

Post by Michael Pro »

I've found the reason - sometimes Self-editor stay unformatted, while in TopLevelEditor everything is ok.
I think, that I gonna rewrite code in few days - if the trouble stay, I'll write about it.
Post Reply