Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#2

AW: RichEdit Schutz mit SelAttributes.Protected wieder aufheben

  Alt 19. Okt 2012, 06:59
Sinn oder Unsinn zu beurteilen überlasse ich Dir, nur ein proof of concept

Delphi-Quellcode:
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.
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat