Search and Replace text in Header

General TRichView support forum. Please post your questions here
Post Reply
DelphiDude
Posts: 17
Joined: Sun Mar 27, 2016 5:15 pm

Search and Replace text in Header

Post by DelphiDude »

I have this code for replacing text in a header and then in the body. But now some of my RTF files throw an index(0) error when trying to process info in the header.

Code: Select all

    begin
    rveDoc.RVHeader.SetSelectionBounds(
      0, rveDoc.RVHeader.GetOffsBeforeItem(0),
      0, rveDoc.RVHeader.GetOffsBeforeItem(0));
    while (rveDoc.RVHeader.SearchText(InSearch,[RVEdit.TRVESearchOption.rvseoMatchCase,
    RVEdit.TRVESearchOption.rvseoDown])) do
        rveDoc.RVHeader.InsertText(InReplace, False);
    end;

    begin
    rveDoc.ActiveEditor.SetSelectionBounds(
      0, rveDoc.ActiveEditor.GetOffsBeforeItem(0),
      0, rveDoc.ActiveEditor.GetOffsBeforeItem(0));
    while (rveDoc.ActiveEditor.SearchText(InSearch,[RVEdit.TRVESearchOption.rvseoMatchCase,
    RVEdit.TRVESearchOption.rvseoDown])) do
        rveDoc.ActiveEditor.InsertText(InReplace, False);
    end;
i get an error on the RVHeader.SetSelectionBounds command of
List Index out of bounds (0) but not on the first time thru. 32nd time thru the searchandreplace it errors out. InSearch = '<HKL_01>' and InReplace = 'HKL, LLP'
DelphiDude
Posts: 17
Joined: Sun Mar 27, 2016 5:15 pm

I have narrowed this down to just 1 document..

Post by DelphiDude »

i have the searchandreplace routine to search headers and activeeditor in seperate search/inserttext statements. But for some reason this one document(RTF file) seems to throw an error with the header code. Could i send it to you or tell me a different way to searchandreplace that processes the text in a header?
Sergey Tkachenko
Site Admin
Posts: 17524
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In the new version of ScaleRichView, RVHeader and RVFooter contain valid information only while they are being edited. I.e. only when ActiveEditor points to them.

You do not need special code for replacing in RVHeader and RVFooter, the code for replacing in ActiveEditor is enough. But before calling it, call StartEditing to activate editing of header/footer/main document.

Please note that any document may have up to 3 headers and footers: for the first page, for odd pages, for even pages. RVHeader/RVFooter will contain header/footer corresponding to the current page.

If you want to make replacement in all headers and footers, you need to modify not RVHeader/RVFooter, but SubDocuments[] property. But they are not editors, you cannot use SearchText/InsertText in them.
Replacements in them should be done like in mailmerge demos http://www.trichview.com/forums/viewtopic.php?t=8
Post Reply