Protect a word or paragraph

General TRichView support forum. Please post your questions here
Post Reply
alexandreq
Posts: 184
Joined: Wed Jan 18, 2012 6:22 pm

Protect a word or paragraph

Post 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
Sergey Tkachenko
Site Admin
Posts: 17560
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
Sergey Tkachenko
Site Admin
Posts: 17560
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As for buttons, if you use TSpeedButton or an analog, do not forget to assign non-zero GroupIndex and AllowAllUp=True.
Post Reply