Solved

ShortCut problem

Posted on 2000-02-14
6
189 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
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!

 
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

Industry Leaders: 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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

628 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