OnCheckProtection?

  • I can't find any info about the event OnCheckProtection. What is it used for, when does it trigger and how do I get it to trigger?

    I am trying to change the down state of a button based on if the cursor is on protected text. I tried to use the OnChangeCursorPos event, but it fails me, For example, if I select a word that is not protected, I click the button which adds protection. I then click on another word that is not protected. The OnChangeCursorPos fires where I do this:

    WPRichText1.TextCursor.GetCharAttr;

    btnLockUnlock.Down := afsProtected in WPRichText1.CurrAttr.Style;


    but afsProtected in WPRichText1.CurrAttr.Style is still true until I move cursor/caret again. Simply clicking between protected and unprotected text works, it just doesn't seem to right after I added protection, as if unselecting of the word on the move is interfering somehow and pulls the wrong attribute. Or I should be doing something before doing the GetCharAttr in the event or after adding protection?

    This is why I was looking into what OnCheckProtection does, but I cannot find any documentation on it.

    • Offizieller Beitrag

    This event is can be used to protect selected objects (only objects!). It is used together with the ProtectedProp property.

    At least one flag must be used in ProtectedProp.

    If this event is specified the ppIsMailMerge and similar flags are overruled!

    Set Result to TRUE if object may not be deleted, otherwise use TRUE

    property OnCheckProtection: TWPTextObjCheckProtectionEvent

    But there is also OnCheckProtection.

    This event can be used to overwrite protection. It is triggered every time

    the protection status of a certain text element is checked.

    The parameter CheckClearSelection is TRUE when the selected characters are checked.

    TWPCheckProtectedEvent = procedure(Sender: TObject; Par: TParagraph;

    posinpar: Integer; var Protection: TWPProtectedMode;

    CheckClearSelection: Boolean) of object;

    Using Protection, the var parameter, you can overrule the internal protection

    TWPProtectedMode = set of (wpNoOverwrite, wpNoInsertPar, wpNoInsertChar,

    wpNoDeletePar, wpNoDeleteChar);

    Use Breakpoint and Trace and follow the CPU to see what happens .