Solved

ShortCut problem

Posted on 2000-02-14
6
188 Views
Last Modified: 2010-04-04
In a form, there are a dbgrid1, a btnOK, a btnClose. The btnOK's caption is &OK, btnClose's caption is &Close. The btnOK onClick does something, and the btnClose OnClick close the form. For the dbGrid1, I set the dgRowselect := true, and I write a code for DBGrid1KeyPress. in the DBGrid1KeyPress, I use dataset.Locate. so when I press a key, It locates the first matched record.
The problem is : when dbgrid is focused, and  I press the 'c', it triggers btnClose OnClick event and closes the form, if I press the 'O', then it triggers the btnOK OnClick event.
I know if I set dbgrid1's dgRowSelect := False, It will not have this problem. But I  really want dgRowSelect := True. So how can I solve the problem?
Thanks

PeterShaw9
0
Comment
Question by:petershaw9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2520577
You could try setting Key to #0 like this:

// Do your lookup stuff here
   Key := #0; // Swallow the key stroke to stop shortcuts...

But the shortcuts MAY get the key before your DB lookup code does.

Cheers,

Raymond.
0
 

Author Comment

by:petershaw9
ID: 2520763
Yes, The shortcut get the key before the locate method. so what can we do?

PeterShaw
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 2520832
Another simple way of doing this would be to Put a TApplicationEvents component on your form (from the additional tab) the writing a OnShortCut event handler. In the handler you can determine if the DBGrid is the active control and if so call the keypress event and then set handled to true to block further processing of the key.

Cheers,

Raymond.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:inthe
ID: 2520999
hi,
not sure if it will help but have you tried changing the forms keypreview setting in object inspector?
0
 

Author Comment

by:petershaw9
ID: 2521143
I test KeyPreview, it doesn't work, because it comes after the shortcut.

I tried RayMond way, it works. I wrote the code like these in the application.onshortcut. but it has a minus defect: if I press the 'Alt' key, then releaseed then press 'c', the form is still be closed.

My code:
const cAlt: Boolean = False;
var wCh : word;
begin
  HourGlassCursor;
  if Msg.CharCode = VK_Menu then
  begin
    cAlt := True;
    ArrowCursor;
    Exit;
  end;

  wCh := Msg.CharCode;

  if dbgrid1.Focused and (not cAlt) and (wCh > 41) and (wCh < 127) then
  begin
    if Msg.CharCode = VK_Escape then
    begin
        Handled := False;
        cAlt := False;
        ArrowCursor;
        exit;
    end;

    dmSupport.oeQryOrgHead.Locate('OH_SHORT', Char(wCh), [loCaseInsensitive, loPartialKey]);
    Handled := True;
  end;

  cAlt := false;
  ArrowCursor;
end;


peterShaw9
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2521166
Hi Peter,

From the Delphi help on TWMKey:

The KeyData field indicates the repeat count, scan code, extended-key flag, context code, and so on. See the Windows help system for a keystroke message such as WM_KEYDOWN for details on the possible values.

You can use the keydata field to determine if the alt key is held down...

Cheers,

Raymond.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Performance of SQL statement 37 147
How to Get Images From Server to Client using App Tethering 1 57
MS Access from Delphi 31 100
Firemonkey Listview item popup menu ? 1 74
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question