Solved

Captureing Arrows from Buttons and CheckBoxes

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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