Insert a page break at runtime

General TRichView support forum. Please post your questions here
Post Reply
enezvaz
Posts: 4
Joined: Mon Jun 01, 2009 8:30 am

Insert a page break at runtime

Post by enezvaz »

Hello,

I have to merge some rtf for a report. On the first page i want the name of the report a page break and on the following pages : file1.rtf, file2. rft....

I test this code with a TSRichViewEdit

myRtf.RichViewEdit.Clear;
myRtf.RichViewEdit.AddNL('My reportName', 0, 0);
myRtf.RichViewEdit.InsertBreakPage;
myRTF.RichViewEdit.LoadRTF('file1.rtf');
myRtf.RichViewEdit.InsertBreakPage;
myRTF.RichViewEdit.LoadRTF('file2.rtf');
myRTF.Format

And i have an error on the first myRtf.RichViewEdit.InsertBreakPage (EListError : indice out of bound (-1)

If i change the code like that :

myRTF.RichViewEdit.InsertText(chr(13));
myRtf.RichViewEdit.AddNL('My reportName', 0, 0);
myRtf.RichViewEdit.InsertBreakPage;
myRTF.RichViewEdit.LoadRTF('file1.rtf');
myRtf.RichViewEdit.InsertBreakPage;
myRTF.RichViewEdit.LoadRTF('file2.rtf');
myRTF.Format

I have a blank page, a page break and on the second page 'My reportname' and then file1.rtf etc

I test the trial version of TSRichviewEdit 2.0.3

Where is my error ?

Thank's in advance
Sergey Tkachenko
Site Admin
Posts: 17571
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

myRtf.RichViewEdit.Clear;
myRtf.RichViewEdit.AddNL('My reportName', 0, 0);
myRtf.RichViewEdit.PageBreaksBeforeItems[myRtf.RichViewEdit.ItemCount-1] := True;
myRTF.RichViewEdit.LoadRTF('file1.rtf');
myRtf.RichViewEdit.PageBreaksBeforeItems[myRtf.RichViewEdit.ItemCount-1] := True;
myRTF.RichViewEdit.LoadRTF('file2.rtf');
myRTF.Format;

There are two main sets of methods for adding content.
Viewer-style methods (like AddNL or LoadRTF) add items to the end of document.
InsertPageBreak (as well as InsertText) is an editing-style method, it inserts a page break in the position of the caret. The caret position is defined only when the document is formatted. After calling viewer-style methods, document is not formatted, and the caret position is undefined (until you call Format). What's why you receive an error.

More info: http://trichview.com/help/viewer_vs_editor.html
enezvaz
Posts: 4
Joined: Mon Jun 01, 2009 8:30 am

Post by enezvaz »

Hello Sergey

Thank's a lot for you reply

It work fine

Best regards
Post Reply