Toggling protected text

  • I have to figure out a way to allow toggling the protective flag. I'm close to a beginner in this document concept and almost lost in it.

    Using D2009, with the latest brew of WPTools 6 (12.12.2012) I have modified the WPT2009Project1 so it contains a TWPRichText from start.

    Code
    wprtEditor.ProtectedTextAttr.BackgroundColor := clYellow;wprtEditor.ProtectedTextAttr.UseBackgroundColor := true;wprtEditor.ProtectedTextAttr.UseTextColor := false;wprtEditor.ProtectedProp := [ppParProtected, ppCheckAllText, ppProtected, ppAllowEditAtTextEnd, ppProtectSelectedTextToo];


    Maybe I've added too many procetion properties? Maybe not relevant, this it the EditOptions:

    Code
    wprtEditor.EditOptions = [wpTableResizing, wpTableColumnResizing, wpObjectMoving, wpObjectResizingWidth, wpObjectResizingHeight, wpObjectResizingKeepRatio, wpObjectSelecting, wpObjectDeletion, wpSpreadsheetCursorMovement, wpActivateUndo, wpActivateUndoHotkey, wpActivateRedo, wpActivateRedoHotkey, wpMoveCPOnPageUpDown, wpAllowCreateTableInTable];


    I try to use this snippet to toggle but all it does is setting the attribute. Undoing has never worked.

    Code
    if afsProtected in wprtEditor.CurrAttr.Style then
      wprtEditor.CurrAttr.DeleteStyle([afsProtected])
    else
      wprtEditor.CurrAttr.AddStyle([afsProtected]);


    What is the right procedure, please?

    When in text surrounded by the \wpprot, I assume the DeleteStyle seeks in both ways for the attribute to remove. Are there navigational functions to seek start and end of a given attribute.

    • Offizieller Beitrag

    Protection is only controlled by ProtectedProp.

    If ppParProtected is set, paragraphs can be ptotected as total using the WPAT_ParProtected attribute (use ASet to change it) and ppProtected activates the protected style afsProtected (similar to bold or italic).

    The other flags control how the protection works, i.e. if it is possible to insert between protected areas. WPTools 7 will add protection through objects, similar to hyperlinks which has the advantage that it is possible to inserd between areas.

    There is a ToggleStyle method which is better to be used that your code.