Page 1 of 1

Protect a word or paragraph

Posted: Wed May 02, 2012 1:49 pm
by alexandreq
Hello sergey

I am trying to add a resource in my editor, protect functions.

First, is there any action that does this?

If not, I tried this code:


Code: Select all

procedure TForm1.rveStyleConversion(Sender: TCustomRichViewEdit; StyleNo,
  UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer);
var FontInfo: TFontInfo;
begin
  FontInfo := TFontInfo.Create(nil);
  try
    FontInfo.Assign(rvs.TextStyles[StyleNo]);
    case UserData of
      TEXT_PROTEGE:
        FontInfo.Protection := [rvprModifyProtect];

      TEXT_BOLD:
        if btnBold.Down then
          FontInfo.Style := FontInfo.Style+[fsBold]
        else
          FontInfo.Style := FontInfo.Style-[fsBold];
    end;
    NewStyleNo := rvs.TextStyles.FindSuchStyle(StyleNo,FontInfo,RVAllFontInfoProperties);
    if NewStyleNo=-1 then begin
      rvs.TextStyles.Add;
      NewStyleNo := rvs.TextStyles.Count-1;
      rvs.TextStyles[NewStyleNo].Assign(FontInfo);
      rvs.TextStyles[NewStyleNo].Standard := False;
    end;
  finally
    FontInfo.Free;
  end;


procedure TForm1.rveCurTextStyleChanged(Sender: TObject);
var fi: TFontInfo;
begin
  IgnoreChanges := True;
  btnBold.Down      := fsBold      in fi.Style;
  btProtege.Down    := fi.Protection = [rvprModifyProtect];
  IgnoreChanges := False;
end;


But this not working, something I forgot?

thanks

Posted: Thu May 03, 2012 1:28 pm
by Sergey Tkachenko
This protection text must protect the selected text from modification. But it does not protect
- from deletion it as a whole
- from changing its text style to another style
- from switching the current text style to this style and insertion of new characters of this style before/after the protected fragment (since this fragment cannot be modified, the inserted character will not be combined with it, so each typed character will create a new single-character text item)

Posted: Thu May 03, 2012 1:29 pm
by Sergey Tkachenko
As for buttons, if you use TSpeedButton or an analog, do not forget to assign non-zero GroupIndex and AllowAllUp=True.