Author: Tomas Rutkauskas
How can I turn off menu accelerators? It's not done with MenuItem.enabled:=false. I
need that because I have set the accelerators 'Delete' and 'Insert' to menu items,
but in some situations those keys need to be "free" for other purposes (when the
user is editing an EditBox, in my case).
Answer:
Your message implies, but doesn't state, that you are using standard windows
shortcuts for Delete (Del key) and Insert (Ins key) features. You want to use them
as the standard when the active control is an edit box but not under other
circumstances.
I had a similar situation and resolved the problem using a TActionList. Use the
OnExecute event to determine if you are using your own or windows processing.
Unfortunately, the windows processing doesn't occur automatically and you have to
handle the action yourself. Here's my solution for Delete:
1 2 procedure TfrmBuildQuery.alExpressionExecute(Action: TBasicAction; var Handled:
3 Boolean);
4 begin5 if Action = aDelete then6 if eValue.Focused then7 {This is the edit control I needed to have windows-like changes}8 begin9 Handled := True; {Stops it from going to the delete action}10 with eValue do11 begin12 {If no selection, then select the char to the right of the cursor.}13 if SelLength = 0 then14 SelLength := 1;
15 {Do the delete}16 SelText := '';
17 end;
18 end19 else20 Handled := False
21 else22 Handled := False;
23 end;