Solved

Captureing Arrows from Buttons and CheckBoxes

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

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 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