• I spent all of yesterday scouring the help file, scouring WPRTFDefs source code etc etc. I was absolutely determined to sort this out myself without posting on this newsgroup. And I am pleased to report that after 10 hours of going around and around in circles, here I am.

    I'm guessing the answer to what I want is as plain as the nose on my face.

    I am using bookmarks as containers for text (possible multi paragraphs), other objects etc. I want to be able to make the text and objects etc within the bookmark tags visible or invisible depending on user set criteria. This gives the user the ability to make whole blocks of text, images etc visible or invisible depending on criteria such as whether a particular document is being dispatched by fax or email.

    I need to be able to hide and restore all of the contents within the bookmark tags and restore it when required exactly as it originally was.

    I've tried using afsHidden, but this doesn't seem to strip out all the carriage returns.

    I've tried storing the object's embeddedtext elsewhere, clearing the embedded text and then restoring it later. This worked well on clearing, but as one might expect it does not restore carriage returns (and I assume it would not restore other objects).

    I then tried looking at the source for wpRTFDefs and looking at the undocumented block properties eg block_par_s etc. I couldn't get these toowork at all. I also couldn't figure out how, once you'd blocked the text, you accessed this new block. Could find no obvious function documented or otherwise to do this.

    So, here's the question(s):

    1. Is there a simple way of making the whole contents between bookmarks visible and invisible including all paragraphs, carriage returns and any objects?

    2. If the answer is no, then how do I access the rtftext as string between the bookmark tags?

    Sorry for the length of the message, just keen to let you know that I do not use this newsgroup lightly!

    • Offizieller Beitrag

    Hi,

    Zitat

    1. Is there a simple way of making the whole contents between bookmarks visible and invisible including all paragraphs, carriage returns and any objects?

    It is not possible to hide the text completely (in V5). You can hide paragraphs inbetween (paprIsHidden in par.prop) but if the BK marks are on different pars one CR between them will remain.

    Zitat

    2. If the answer is no, then how do I access the rtftext as string between the bookmark tags?

    There is no "RTF text", that operation will always be a Load&Save operation.

    You can use
    wp.TextCursor.SpeedSelectFromTo(
    bookmark_start.ParentPar, bookmark_start.ParentPosInPar,
    bookmark_end.ParentPar, bookmark_end.ParentPosInPar);
    s := wp.SelectionAsString;
    That should preserve the CRs.

    bookmark_end = bookmark_start.EndTag!

    Kind Regards,

    Julian Ziersch

  • Thanks Julian,

    I was keen to avoid changing the selection. I was rather hoping it could all be done in the background without having to then restore the previous selstart sellength. Is there anyway of grabbing the rtftext between the tags without actually selecting it?

    Thanks,

    Mark

  • Hi Julian,

    Took my time testing this one, but it works a treat.

    However, once I have my text/data in a stream I can insert it at cursor position, but this is not what I need to do. I need to identify a bookmark and insert at the bookmark position without moving the code.

    I have looked at RTFData.insertBlock but does not seem to be what I need and I cannot find any other way of doing it.

    Can you let me know what I should be doing to insert the stream data and if possible a little snippet of code.

    Thanks

    Mark

    • Offizieller Beitrag

    Hi,

    If you have a bookmark (TWPTextObj) you can assign formatted text to its property EmbeddedText tio clear its contents, move inside the object and load your text here.

    It does not work without moving the cursor so you need to save the cursor position before you exectute this code. (CPPosition)

    Only if you insert plain texct you can assign that directly to property EmbeddedText

    Julian

  • Have you looked at RTFData.InsertRTFData?

    We also use bookmarks in our documents to insert specific data from any format and i have managed to avoid changing the selection.

    To use InsertRTFData you do need to load the content into a TWPRTFDataBlock first.

    Code
    lvStrStream := TStringStream.Create(pvString);
    readerclass := WPRichText1.Memo.GetReaderClass(lvStrStream, TextLoadFormat);
    rtf := WpRichText1.RTFData.LoadFromStreamWithReader(lvStrStream, reader, true, nil);
    WPRichText1.RTFData.InsertRTFData(rtf, par.RTFData, par, pos_in_par, newpos, false);