Solved

Captureing Arrows from Buttons and CheckBoxes

Posted on 2000-02-13
4
148 Views
Last Modified: 2010-04-04
I'm a junior program on the junior side of life and I'd like to know how to capture the down and up arrow key stroke from bitBtns and checkboxes.  I can do it at form level thanks to my boss, but I'd like to create a new component that gives me access to these keystrokes.  Any ideas?
0
Comment
Question by:toesable
  • 3
4 Comments
 

Accepted Solution

by:
ellessar earned 100 total points
ID: 2517954
There are two ways to do this outside of your form:

1) You can trap the message that windows sends out.

EG:

type

  TTextBox = class(TCustomControl)
    private
    procedure WMChar(var Message: TWMChar); message WM_CHAR;
    ...
  end;

Then in the implementation section:

procedure TTextBox.WMChar(var Message: TWMChar);
begin
  if Chr(Message.CharCode) = #13 then
    ProcessEnter
  else
    inherited;
end;

The inherited statement searches backward through the class hierarchy and invokes the first message handler with the same ID as the current method, automatically passing the message record to it. If no ancestor class implements a message handler for the given ID, inherited calls the DefaultHandler method originally defined in TObject.

2) If you are descending your component from a TWinControl you can use the OnKeyPress event.
EG:
Type

  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure Memo1KeyPress(Sender: TObject; var Key: Char);
    ...
  end;

and in the implementation section:

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  MessageDlg(Key + ' has been pressed', mtInformation, [mbOK], 0)
end;

0
 

Author Comment

by:toesable
ID: 2518444
Thank you.  This is similar to what my boss gave me but your comments really make the difference.  
0
 

Author Comment

by:toesable
ID: 2518454
ellessar, not sure what happened, I didn't changed the points, but it only says 10 here instead of 100 so if you don't get the full amount let me know, I'll pass you some more.
0
 

Author Comment

by:toesable
ID: 2518930
ps, didn't work for up and down arrow keys, but my boss convinced me that I wanted to controll of those things from the form not in the component and this really was helpful for other things.  Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 263
Delphi inherited method 6 63
How to build JSON File in Delphi 6 3 17
Firemonkey DbLookupComboBox equivalent ? 2 38
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

861 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now