Page 1 of 1

List out of bounds Exception in TRVEditRVData.GetCurItemNo

Posted: Tue Apr 22, 2008 7:16 am
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.

Posted: Tue Apr 22, 2008 7:46 am
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;

Posted: Tue Apr 22, 2008 11:54 am
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.

Posted: Thu Apr 24, 2008 3:05 am
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?

Posted: Thu Apr 24, 2008 6:06 am
by Michael Pro
Or maybe it's simplier to check rvstEditorUnformatted flag in editor state before actions updating?

Posted: Thu Apr 24, 2008 6:26 am
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.

Posted: Thu Apr 24, 2008 10:03 am
by Michael Pro
Won't help (((
Sometimes RVData is in rvstForceStyleChangeEvent state - and it won't help ((((

Posted: Thu Apr 24, 2008 3:53 pm
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.

Posted: Fri Apr 25, 2008 3:13 am
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.