Page 1 of 1

Load huge text from database to RichViewEdit

Posted: Wed May 18, 2016 4:32 pm
by saeid2016
Hello,

I want to load huge text from database to RichViewEdit. for example one of books stored on my database has 2500 pages.

I use this code:

Code: Select all

RichViewEdit.AddText(MyQueryObject.FieldByName('BookText').AsString, 0);
But it is very slow, What is the fastest way to do this?

My Database is SQLite.

Posted: Wed May 25, 2016 7:03 pm
by saeid2016
Any one have good suggestion?

Posted: Wed May 25, 2016 9:20 pm
by Sergey Tkachenko
Probably, not text addition, but formatting takes a lot of time.

If you do not use bidirectional text or text in exotic language, you can change RVStyle.TextEngine from Uniscribe to Windows, it will be much faster.

Posted: Thu May 26, 2016 6:00 am
by saeid2016
Sergey Tkachenko wrote:If you do not use bidirectional text or text in exotic language, you can change RVStyle.TextEngine from Uniscribe to Windows, it will be much faster.
My text is Arabic.

Posted: Thu May 26, 2016 7:41 am
by Sergey Tkachenko
You can save this field to a text file, then open in the ActionTest demo.
If it loads it faster, the problem is in your application.
If the loading time is the same, this is a maximal possible speed.

Please note that window width affects the speed of formatting. Usually, in the wider window, formatting is faster (because the number of lines is lesser).

Posted: Thu May 26, 2016 8:47 am
by saeid2016
Sergey Tkachenko wrote:You can save this field to a text file, then open in the ActionTest demo.
If it loads it faster, the problem is in your application.
If the loading time is the same, this is a maximal possible speed.

Please note that window width affects the speed of formatting. Usually, in the wider window, formatting is faster (because the number of lines is lesser).
Because of bigness of my texts, I want to store the books page by page. I store each page as a record in database.

Then I load the texts page by page in RichViewEdit but I don't want the End user understand it.

I mean that I want to End user think the book has loaded completely. but I have loaded one page and when the end user wheels mouse up or down I load previous or next page.

For do this, I should disable RichViewEdit ScrollBar and use an other scrollBar.

Is it possible to insert text to RichViewEdit before or after caret position so that the caret position not changed. I mean that the user not understand this insertion and only see the inserted text ofter scrolling up or down?

Excuse me for bad English. Please help.

Posted: Thu May 26, 2016 8:53 am
by Sergey Tkachenko
The fastest way to add content to the end of the document:
- add new content using Add* methods, for example using AddTextNL. New content must start a new paragraph.
- call FormatTail.

If you want removing paragraphs at the beginning, call DeleteParas (do not call Format after that).

These methods were designed for implementing chat and log windows, but I believe they can be used to load text page by page.

Posted: Thu May 26, 2016 9:05 am
by saeid2016
How I add text to the begin of the document so that current visible items not change after adding text?

Posted: Thu May 26, 2016 9:43 am
by Sergey Tkachenko
First, about the insertion.

There are no special non-editing methods for insertion at the beginning, so I suggest to position the caret at the beginning and call InsertText (probably, you need to add #13#10 to the end of inserted text).
Turn off undo recording (set UndoLimit = 0), otherwise it will be slow.

How to keep position.
Before insertion, store
StoredItemNo := rv.ItemCount and StoredTop returned by rv.GetItemClientCoords(0, Left, StoredTop).
After insertion, get rv.GetItemClientCoords(rv.ItemCount - StoredItemCount, Left, Top).
Call rv.ScrollTo(StoredTop - Top)
(I may be miscalculated, but I believe you understand the idea)

To prevent flickering, put this code inside rve.BeginUpdate ... rve.EndUpdate