Switch selected information in tdbrichviewdit to bold/normal

General TRichView support forum. Please post your questions here
Post Reply
jota
Posts: 48
Joined: Fri Sep 16, 2011 10:56 am

Switch selected information in tdbrichviewdit to bold/normal

Post by jota »

I have next code for that. I click on a type TSpeedButton to launch the procedure and all is well

const
{ Parameters for ApplyStyleConversion }
TEXT_BOLD = 1;
TEXT_ITALIC = 2;
TEXT_UNDERLINE = 3;

{ bold, italic, underline }
procedure TSDIAppForm.btnEstiloFuenteClick(Sender: TObject);
var
button: TSpeedButton;
begin
button := Sender as TSpeedButton;
{ constants TEXT_BOLD, TEXT_ITALIC and TEXT_UNDERLINE are
assigned to the tags of corresponding buttons }
EditorNotas.ApplyStyleConversion(Button.Tag);
end;


I need to do the same with the right mouse button from the tdbrichviewedit popup menu. What would be the necessary code

Thank in advance.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you want to implement the same command executed by several controls (a button and a menu item), the best way is using actions.

1) Place TActionList component on the form. In this action list, using "New Action" command, add 3 actions. Rename them to actBold, actItalic, actUnderline
2) Assign their tags equal to TEXT_* constants, i,e. actBold.Tag=1, actItalic.Tag=2, actUnderline.Tag=3.
3) Assign OnExecute event for all these actions:

Code: Select all

procedure TForm1.ActionTextStyleExecute(Sender: TObject);
var Action: TAction;
begin
  Action := Sender as TAction;
  Action.Checked := not Action.Checked;
  ActiveEditor.ApplyStyleConversion(Action.Tag);
end;
4) In OnCurTextStyleChanged, change

Code: Select all

  btnBold.Down      := fsBold      in fi.Style;
  btnItalic.Down    := fsItalic    in fi.Style;
  btnUnderline.Down := fsUnderline in fi.Style;
to

Code: Select all

  actBold.Checked      := fsBold      in fi.Style;
  actItalic.Checked    := fsItalic    in fi.Style;
  actUnderline.Checked := fsUnderline in fi.Style;
5) In OnStyleConversion, change

Code: Select all

        if btnBold.Down then
to

Code: Select all

        if actBold.Checked then
The same for Italic and Underline
7) Delete btnEstiloFuenteClick
6) Assign the actions for menu items and buttons.
jota
Posts: 48
Joined: Fri Sep 16, 2011 10:56 am

Switch selected information in tdbrichviewdit to bold/normal

Post by jota »

Hello

Your solution works perfectly

Thank you very much for your time and your attention
Post Reply