What is the best method to protect text?

  • I have read numerous posts on protecting text in this forum, but none have been helpful.

    I have a rtf document that serves as a template for my users. This document contains serveral paragraphs and several mail merge fields. Currently, users create new documents based off of this template with merged data, but are able to freely modify the results. What I would like to do is allow my users to add paragraphs to this document without allowing them to delete any of the original paragraphs or merge fields. Please explain:

    1) How do I protect all of the text of the template, programatically?

    2) How do I allow users of the template to add paragraphs (between existing paragraphs) without allowing them to delete any of the text?

    3) Should the administrator need to modify the template, what needs be be done to allow this?

    I have tried code like this to enable the protection:

    This protects the text from overtyping, but the user can still select it and press delete. It also allows the user to insert empty paragraphs between paragraphs but only occassionally can they enter text, weird. Also, backspace or delete will not allow them to delete the empty paragraphs that they inserted.

    D2007
    WPTool 5.39

    • Offizieller Beitrag

    Hi,

    to protected selections You need to add flag ppProtectSelectedTextToo.

    Your code is good to protect a group of paragraphs.

    Insertion of paragraphs is not expected - You could trap the OnKeyDown event to insert paragraphs on demand:

    if (Key=VK_INSERT)
    and (WPRichText1.ActiveParagraph.AGet(WPAT_ParProtected,0)<>0)
    then
    begin
    WPRichText1.ActiveParagraph :=
    WPRichText1.ActiveParagraph.AppendNewPar(false);
    WPRichText1.ActiveParagraph.ADel(WPAT_ParProtected);
    WPRichText1.ReformatAll(false, true);
    key := 0;
    end;

    Zitat

    3) Should the administrator need to modify the template, what needs be be done to allow this?

    If ProtectedProp is empty, nothing is protected.

    Julian