Title: ProtectAction for RichEdit
Question: This will add the RichEditProtect to the standard actions list for an actionlist, similar to RichEditBold. Allows you to protect text from changes in a TRichEdit.
Answer:
unit RICHACT; {Rich Edit Actions}
interface
uses
ActnList
,StdCtrls
,ComCtrls
,ExtActns
;
type
TRichEditProtect = class(TRichEditAction)
public
procedure ExecuteTarget(Target: TObject); override;
procedure UpdateTarget(Target: TObject); override;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterActions('Formatt'
,[
TRichEditProtect
]
,nil);
end;
{ TRichEditProtect }
procedure TRichEditProtect.ExecuteTarget(Target: TObject);
begin
if Target is TCustomRichEdit then
CurrText(Target as TCustomRichEdit).Protected:=true;
end;
procedure TRichEditProtect.UpdateTarget(Target: TObject);
begin
Enabled := Target is TCustomRichEdit;
Checked := Enabled and (CurrText(Target as TCustomRichEdit).Protected);
end;
end.
"RegisterActions" is only available in the IDE, so you'll need to create a new "package" (under Component/Install Packages/New) and add this unit to it. Once installed, the item will appear in the "New Standard Actions" list for action lists.