How to know if I'm trying to change a protected text?

  • Hi, I have a few parts of my text that are protected using this:

    So all the text between {$ and } are protected.. I already use ProtectedTextAttr to change the background of this text, but the users still are confused when they try to change this text and "nothing happens" (the cursor just move forward as you type)..

    When my WPRichText is ReadOnly I use the OnKeyDown event and fire a message on the screen that says "Document is blocked for edition"..

    How could I do the same thing with protected parts of the text? I mean, when the user try to change something that is protected, I'd like to ShowMessage something instead of just let him type and nothing happens besides the cursor move forward.

    Where and how can I check that?

    Thanks!

  • Zitat von wpsupport

    Check the source for FMemo.IsProtected - that's a good example, i.e. in TWPCustomRtfEdit.DragOver.

    Cool, I was able to achieve that using this:

    Code
    if WPRichText.Memo.IsProtected(WPRichText.ActivePar,WPRichText.ActivePosInPar, True) <> [] then
        Application.MessageBox('Esta parte do texto está protegida contra alterações!','Aviso',MB_OK+MB_ICONWARNING);

    I'm just not sure about what is the last parameter for (CheckClearSelection) in IsProtected..

    I put this on the OnKeyPress event of the WPRichText, is this the best place?

    Thanks!