[SOLVED]How to make a shortcut key for Action work only on Memo1 lazarus / 31-LCL ---------------------------------------------------------------------- tomitomy · 2017-10-27 02:28 Hi, everybody, I have a question about Action, there are Memo1 and Memo2 on the form. I just want the shortcut key of Action to be valid in Memo1 and invalid in other places. How can I achieve it? Test Code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   TForm1 = class(TForm)    Memo1: TMemo;    Memo2: TMemo;    procedure FormCreate(Sender: TObject);  private    Action1: TAction;    ActionList1: TActionList;    procedure Action1Execute(Sender: TObject);  end; uses  LCLProc; procedure TForm1.FormCreate(Sender: TObject);begin  ActionList1 := TActionList.Create(self);  Action1 := TAction.Create(self);  with Action1 do  begin    ActionList := ActionList1;    ShortCut := TextToShortCut('Ctrl+A');    OnExecute := @Action1Execute;  end;end; procedure TForm1.Action1Execute(Sender: TObject);begin  ShowMessage('Action For Memo1');end; ---------------------------------------------------------------------- howardpc · 2017-10-27 08:07 You can design your action's OnExecute to be as specific as you want. e.g. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   TForm1 = class(TForm)    Memo1: TMemo;    Memo2: TMemo;    procedure FormCreate(Sender: TObject);  private    ActnList: TActionList;    Memo1Action: TAction;    procedure Memo1ActionExecute(Sender: TObject);  end; var  Form1: TForm1; implementation procedure TForm1.FormCreate(Sender: TObject);begin  ActnList:=TActionList.Create(Self);  Memo1Action:=TAction.Create(ActnList);  with Memo1Action do begin    ActionList:=ActnList;    ShortCut:=TextToShortCut('Ctrl+A');    OnExecute:=@Memo1ActionExecute;  end;end; procedure TForm1.Memo1ActionExecute(Sender: TObject);begin  Memo1.Color:=RGBToColor(Random(256), Random(256), Random(256));end; ---------------------------------------------------------------------- tomitomy · 2017-10-27 08:52 Quote from: howardpc on October 27, 2017, 10:07:25 amYou can design your action's OnExecute to be as specific as you want. Thank you howardpc, but in this case, Memo2's shortcut Ctrl+A will not work properly, unable to perform "select all" operation. I hope Action's shortcut only affect Memo1. ---------------------------------------------------------------------- taazz · 2017-10-27 09:25 Quote from: tomitomy on October 27, 2017, 10:52:58 amThank you howardpc, but in this case, Memo2's shortcut Ctrl+A will not work properly, unable to perform "select all" operation. I hope Action's shortcut only affect Memo1. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  ActnList:=TActionList.Create(Self);  Memo1Action:=TAction.Create(ActnList);  with Memo1Action do begin    ActionList:=ActnList;    ShortCut:=TextToShortCut('Ctrl+A');    OnExecute:=@Memo1ActionExecute;    OnUpdate := @Action1Update;  end;end; procedure form1.Action1Update(Sender: TObject);begin  Action1.enabled := activecontrol = TMemo1;end; ---------------------------------------------------------------------- howardpc · 2017-10-27 09:29 OnUpdate gives you limited customisation. But AFAIK it does not let you redfine the action for specific controls, so that (say) Ctrl-A has different effects in Memo1 and Memo2. Disabling Ctrl-A for Memo2 is rather different from giving Ctrl-A a new effect in Memo2 compared to Memo1. ---------------------------------------------------------------------- tomitomy · 2017-10-27 10:09 Thank you taazz. I tested your code. It's exactly what I need. Thank you very much! Quote from: howardpc on October 27, 2017, 11:29:31 amOnUpdate gives you limited customisation. But AFAIK it does not let you redfine the action for specific controls, so that (say) Ctrl-A has different effects in Memo1 and Memo2. Disabling Ctrl-A for Memo2 is rather different from giving Ctrl-A a new effect in Memo2 compared to Memo1. I'm sorry howardpc, my English is poor, I can not understand the content of your post, Google translation results I can not understand also. But thank you for your help. ---------------------------------------------------------------------- jamie · 2017-10-29 00:59 what he means is this, having CTRL-A perform different duties between Memo1 and Memo2 is difficult. But disabling them is easier. I believe that was his meaning. ---------------------------------------------------------------------- tomitomy · 2017-10-29 02:10 Quote from: jamie on October 29, 2017, 02:59:21 amwhat he means is this, having CTRL-A perform different duties between Memo1 and Memo2 is difficult. But disabling them is easier. I believe that was his meaning. Thank you, jamie, I understand.