looping through headers/footers v5

  • doing this for my merging and counting in v4.22. But the workontext doesn't work anymore. How do I use the Activetext or whatever, instead?

    • Offizieller Beitrag

    >> Merge in all texts (header and footer)

    WPRichText1.MergeText( '' , TRUE );

    Important
    The MergeText procedure will work with the DisplayedText or the Body text, not the ActiveText text which can be selected with
    "WPRichText1.WorkOnText := wpHeader" - So, if you need to merge in the header ONLY you need to work with the RTFDataBlock directly.
    How this can be done has been described here:
    http://wpcubed.com/forum/viewtopic.php?p=3790#3790

  • great that's easier.

    Q: I'll also have to do my text counting loops in all the headers and footers so I still need to know how to access each one. Once I have access to it, I do a gettextlen and I do cpmoves through it checking for styles and such.

    • Offizieller Beitrag

    The 'WorkOnText' property now works.

    But insted of using gettextlen and cpmoves I would suggest code like this:


    Julian

  • having some trouble with this, and counting of characters is a very important part of my applications.

    for this particular function, I just need to count all the characters in the document in the body and headers/footers. I don't need to check styles and things.

    GetTextLen always returns 0, no matter what.

    par.charcount produces what seems like almost random results, sometimes it seems to be double the actual amount, sometimes not.

    What does charcount do exactly?

    a completely blank rtf returns a count of 7141732


    • Offizieller Beitrag

    It seems so that in your code 'len' is initialized at the wrong place and the body was counted in each round.


    end;

    par.CharCount is certainly not random - it is the count of characters and/or objects in this paragraph. It is a variable, not a property to speed things up. But maybe in your tabes to table rows there was some text for any reason - so I added the line
    if not (par.ParagraphType in [wpIsTable,wpIsTableRow]) then


    HeaderFooter also contains the body text ('Kind' = wpIsBody) -
    HeaderFooter is actually just a reference to the RTFDataCollection object, the same as WPRichText.Memo.RTFData.


    Julian

  • ok it's working better, but I'm not sure about the counts it is returning

    here's some examples

    start with a blank rtf. totallen=0 ok that's good

    Code

    type in one letter

    Code
    a


    this counts as 2, but I'd expect it to be 1

    type in another letter

    Code
    ab


    this counts as 3, I'd expect 2

    add a return

    Code
    ab


    this comes back as 4, I'd expect 3 or 4. I guess depending on if it counts the CR and LF seperately(4) or together(3).

    what could the other counts be coming from? I only want it to count visual text and other characters like tab space CR LF, etc. GetTextLen 'seemed' to do it this way. I'm not using any tables or anything like that in this example, just a completely blank rtf.

    This routine will work great for this if I sort out the extra character, but later on I'll have to split out each section and check for styles within each section. The ability to count characters VERY reliably is a most important feature for me.

  • I'll have to come back to this later, but there does seem to be a little difference in this and the old GetTextLen. I guess it has to do with counting the 'paragraph' vs CR+LF?

    pressing enter using this adds 1, GetTextLen adds 2 when you press enter.

  • It seems to work more like this

    with the new count, it initially has one extra count, for the paragraph I suppose. So adding one letter makes it 2. Every time you press enter after that, 1 is added.

    With GetTextLen, it is initially 0. If you enter one letter, the count is one, and every time you press return, the count increments by 2.

    So I guess I could do the +2, but it will probably always be 1 more than gettextlen.

    Like I said, I will have to do a pretty complex counting procedure later on, so I'll be able to test it more then to see if I can tweak it to give me what I want.