Page 1 of 1

Insert a page break at runtime

Posted: Mon Jun 01, 2009 11:04 am
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

Posted: Mon Jun 01, 2009 5:11 pm
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

Posted: Tue Jun 02, 2009 8:33 am
by enezvaz
Hello Sergey

Thank's a lot for you reply

It work fine

Best regards