Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Input in a edit control and accelerator keys


This question is answered.


Permlink Replies: 3 - Last Post: Dec 3, 2015 4:04 AM Last Post By: Vladimir Shvetsov
Vladimir Shvetsov

Posts: 12
Registered: 2/18/05
Input in a edit control and accelerator keys  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 2, 2015 5:20 PM
Hi,
I have a TEdit control on a form, the form is a child of a main form.
There are actions with accelerator keys Del and BkSp, linked to a menu items and ToolButtons of the main form. When I input text in a edit control and press Del or BkSp, the actions are executed instead of deleting characters in a control. How to "switch off" accelerators, when focus is on the edit control?
Thank you.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Input in a edit control and accelerator keys
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 2, 2015 6:55 PM   in response to: Vladimir Shvetsov in response to: Vladimir Shvetsov
Vladimir wrote:

How to "switch off" accelerators, when focus is on the edit control?

You can override the form's virtual IsShortCut() method to return False if
an edit control is currently focused when the Delete or Backspace key is
being pressed. For example:

class TMyForm : public TForm
{
...
public:
    ...
    DYNAMIC bool __fastcall IsShortCut(TWMKey &Message);
...
};
 
bool __fastcall TMyForm::IsShortCut(TWMKey &Message)
{
    if (dynamic_cast<TCustomEdit*>(ActiveControl) != NULL)
    {
        if ((Message.CharCode == VK_DELETE) || (Message.CharCode == VK_BACK))
            return false;
    }
    return TForm::IsShortCut(Message);
}


--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Input in a edit control and accelerator keys
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 2, 2015 6:57 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy wrote:

You can override the form's virtual IsShortCut() method to return
False if an edit control is currently focused when the Delete or
Backspace key is being pressed.

Here is some more information if you want to know exactly how the VCL processes
keystrokes at runtime:

A Key’s Odyssey
http://edn.embarcadero.com/article/38447

--
Remy Lebeau (TeamB)
Vladimir Shvetsov

Posts: 12
Registered: 2/18/05
Re: Input in a edit control and accelerator keys  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 3, 2015 4:04 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thank you. The article is very good.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02