Bad RTF table causing RichView to error

General TRichView support forum. Please post your questions here
Post Reply
jgkoehn
Posts: 315
Joined: Thu Feb 20, 2020 9:32 pm

Bad RTF table causing RichView to error

Post by jgkoehn »

Greetings Sergey,

I am getting an error in this code:
First chance exception at $75D50144. Exception class EListError with message 'List index out of bounds (-1). TRVList is empty'.
I know it is bad RTF code on a Table (however, I can't always fix the bad RTF tables. These can be from users. Is there a way to handle this more robustly?)

Current code in RV22.2

Code: Select all

function TRVRTFReader.DoTable(WhatHappens: TRVRTFTableEventKind): Boolean;
begin
  Result := True;
  UpdateMarker;
  if Assigned(FOnTable) then
    FOnTable(Self, WhatHappens, Result);
  AfterTableRow := WhatHappens in [rvf_tbl_RowEnd, rvf_tbl_TableEnd,
    rvf_tbl_TableForcedEnd];
end;
Ideas?
Sergey Tkachenko
Site Admin
Posts: 17867
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Bad RTF table causing RichView to error

Post by Sergey Tkachenko »

This exception happens in try..except block, and finally LoadRTF function simply returns False.
The exception is not noticeable unless debugging in Delhi IDE.
jgkoehn
Posts: 315
Joined: Thu Feb 20, 2020 9:32 pm

Re: Bad RTF table causing RichView to error

Post by jgkoehn »

Is this related Sergey?
It is showing up in the Richview interface but not always.
Attachments
Screenshot 2025-07-13 072233.png
Screenshot 2025-07-13 072233.png (30.67 KiB) Viewed 1846 times
jgkoehn
Posts: 315
Joined: Thu Feb 20, 2020 9:32 pm

Re: Bad RTF table causing RichView to error

Post by jgkoehn »

It is highly possible I've done something wrong and just have no idea on how to get to the bottom of it.
Sergey Tkachenko
Site Admin
Posts: 17867
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Bad RTF table causing RichView to error

Post by Sergey Tkachenko »

If the error text is shown on TRichView itself, this mean that an exception happens while drawing content.
Most probably. it happens because TRichView is not formatted.
Do not forget to call Format after loading.
jgkoehn
Posts: 315
Joined: Thu Feb 20, 2020 9:32 pm

Re: Bad RTF table causing RichView to error

Post by jgkoehn »

I have found the problem but not sure why it exists:

Code: Select all

      //SHIFT not pressed (UP)
    if GetKeyState(VK_SHIFT) and $ff00 = 0 then begin
      try
        s := reader.GetItemTag(i);
        p := Pos(':', s);
        if (p>0) and(p<6) then continue;
        reader.SetItemTag(i, ''); <------------if I comment this out I am fine
      except
        on E: Exception do begin
          OutputDebugString(PChar('WMAfterPaste GetItemTag error: ' + E.Message));
          Continue;
        end;
      end;
    end;
reader.SetItemTag(i, ''); <------------if I comment this out I am fine

I have tried format, reformat, formattail, SetItemTagEd and many more items. This is in a Timer event. I can run through it just fine in Delphi12.3 debugger but as soon as I click on another open TRichViewEdit I get an this TRichViewItem list error.
The Style type is set to rvf_sInsertMerge.

And then I just start getting a cascade of TRVItemList errors......until my program crashes basically.
standay
Posts: 293
Joined: Fri Jun 18, 2021 3:07 pm

Re: Bad RTF table causing RichView to error

Post by standay »

You might check that i <> -1, and i <= reader.itemcount-1.

Stan
Post Reply