Solved

Captureing Arrows from Buttons and CheckBoxes

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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