D2: Protecting and UNprotecting text in RichEdit
I have played a little with protected text in the RichEdit control.
I discovered, that when you have made some text protected by setting the
TTextAttributes Protected Property to true, you can't change it back to unprotected
without invoking the OnProtectChange Event.
This means: since the text is protected, you aren't allowed to change it
back to unprotected!
In the help file (OnProtectChange) it reads:
"To set or unset text as protected, use the run-time Protected property
of the TTextAttributes object."
Smells like a bug to me, either in Delphi2 or in the Help file.
THE SOLUTION:
is to make a signal to the event, that this change is okay. By setting its
AllowChange variable to true, the change can be allowed.
For instance by having the global Boolean variable FChangeOK
and do something like this:
..
{unprotect text}
FChangeOK := True;
RichEdit1.SelAttributes..Protected := False;
FChangeOK := False;
..
procedure TMainForm.RichEdit1ProtectChange(Sender: TObject; StartPos,
EndPos: Integer; var AllowChange: Boolean);
begin
if FChangeOK then begin
AllowChange := true;
end
end;
Isn't that silly?
Regards,
Kim Oechsle Hansen
----------------------------------------
AKA-PRINT A/S
Sommervej 8
8210 Aarhus V
Denmark
Phone: +45 8675 0033
Fax: +45 8675 0133
e-mail: akapr...@inet.uni-c.dk