Solved

Captureing Arrows from Buttons and CheckBoxes

Posted on 2000-02-13
4
154 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
[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
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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 136
Magic Software info 18 156
Firemonkey DbLookupComboBox equivalent ? 2 79
can i put an image from resource into image tag ? 6 42
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

752 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