WPCubed Product Support

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:

// Protege texto entre {$***}
        with WPRichText do begin

          Finder.Clear;
          Finder.ToStart;

          while Finder.Next('{$*}') do
            Finder.FoundAttr.IncludeStyle(afsProtected);

          ReformatAll(True,True);
          Modified := True;

        end;

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!

#1 ♥ 0
5.9k Views 2 users read 2 min
support

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

#2 ♥ 0

@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:

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!

#3 ♥ 0
support

CheckClearSelection should be set to true if text is selected. In this case entering data will clear thge selection and so more text is affected.

OnKeyPress Comes later than OnKeyDown. I would check in OnKeyDown but not for special keys such as Cursor.

#4 ♥ 0
This category is archived. No new posts are possible.