Page 1 of 1

Errors in Richviewedit DropFile

Posted: Thu Jul 29, 2021 9:05 pm
by standay
Hi,

If I try to clear the existing data in my rve in the dropfile method, I get errors reported by madexcept. Mostly it's a list index out of bounds I think from the tcustomrvdata.getitem call. Not sure what the problem is. All I have in dropfile now is

RichViewEdit1.Clear;
exit;

If I load a large file, it loads OK. But if I try to load a smaller file, it throws the error. It still loads and appears to work, but the errors are concerning.
If I load a smaller file, then a larger one it's OK. But as soon as I try to drop a smaller file onto a larger one it errors IF I scroll the larger file down a ways first. If I leave the larger file scrolled all the way up it will let me drop the smaller file.
If I remove any calls to Clear or ClearAll it will work, but just inserts the smaller file into the larger one which is not what I want.

I've tried InsertText and SetTextBuf and both have errors as above.

Any ideas appreciated.
Image7.png
Image7.png (79.2 KiB) Viewed 6492 times

Re: Errors in Richviewedit DropFile

Posted: Fri Jul 30, 2021 1:00 pm
by Sergey Tkachenko
Can you give me the step-by-step instructions to reproduce this problem?
I believe it happens when inserting a text file in some specific place of a specific document.

Re: Errors in Richviewedit DropFile

Posted: Sat Jul 31, 2021 12:22 pm
by standay
Sure...

Start new vcl project.
Add a trichviewedit.
Put "RichViewEdit1.Clear;" into DropFile method:

Code: Select all

procedure TForm1.RichViewEdit1DropFile(Sender: TCustomRichViewEdit;
  const FileName: TRVUnicodeString; var DoDefault: Boolean);
begin
  RichViewEdit1.Clear;
end;
Run app.
Drop a large text file into rve (I use a large PAS source file).
It should load and come up scrolled to the bottom of the file, with text selected. Leave the scroll where it is, and click in the rve to deselect text.
Drop a smaller text file into rve. Should see the list out of bounds error now.

Does not seem to be related to the insert function as such, but the Clear or ClearAll calls. All I know is I have not been able to fix it.

Re: Errors in Richviewedit DropFile

Posted: Sat Jul 31, 2021 8:11 pm
by Sergey Tkachenko
The component does not expect that you clear content in this event. It expects that you insert something at the caret position.
The exception occurs when the component tries to select the inserted content.

Re: Errors in Richviewedit DropFile

Posted: Sat Jul 31, 2021 9:16 pm
by standay
OK. I worked around it by grabbing the filename from there, setting dodefault to false. Then I use the filename in my app idle and load there. So that will work.

Thanks for looking at it.