unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,richedit;
type
TRichedit=Class(ComCtrls.TRichedit)
private
FAllowOneUnProtection: Boolean;
published
procedure CNNotify(
var Message: TWMNotifyRE);
message CN_NOTIFY;
Property AllowOneUnProtection:Boolean
read FAllowOneUnProtection
write FAllowOneUnProtection;
End;
TForm1 =
class(TForm)
RichEdit1: TRichEdit;
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Lock(RichEdit: TRichEdit);
begin
with RichEdit
do
begin
AllowOneUnProtection := false;
SelAttributes.
Protected := true;
end;
end;
procedure UnLock(RichEdit: TRichEdit);
begin
with RichEdit
do
begin
AllowOneUnProtection := true;
SelAttributes.
Protected := false;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Lock(RichEdit1);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UnLock(RichEdit1);
end;
{ TRichedit }
procedure TRichedit.CNNotify(
var Message: TWMNotifyRE);
begin
inherited;
if AllowOneUnProtection
then
begin
with Message do
case NMHdr.code
of
EN_PROTECTED:
with ENProtected.chrg
do Result := 0;
end;
AllowOneUnProtection := false;
end;
end;
end.