Load huge text from database to RichViewEdit

General TRichView support forum. Please post your questions here
Post Reply
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Load huge text from database to RichViewEdit

Post 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.
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Post by saeid2016 »

Any one have good suggestion?
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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).
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
saeid2016
Posts: 72
Joined: Wed Mar 16, 2016 11:56 am

Post by saeid2016 »

How I add text to the begin of the document so that current visible items not change after adding text?
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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
Post Reply