Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to write Components which handle ENTER-Key like TAB-Key Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Jul-03
Category
VCL-General
Language
Delphi 6.x
Views
91
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Alex Schlecht

Standard-behaviour of controls when pressing ENTER-KEY is a BEEP-Sound. But how to 
write Components which handle ENTER-Key like TAB-Key?

Answer:

This Article will show how to write Components which will handle the ENTER-Key in 
the same behaviour like the TAB-Key. As Sample I will take a TEdit-Component but it 
should work on oll other components with OnKeyPress-Event. 

Create a new Component from TEdit with a new property: 

EnterNextCtrl: Boolean

If this is TRUE (standard), the Focus will jump to next Control if the user press 
ENTER. If it is FALSE it will show standard-behaviour (beep). This functionality is 
included in OnKeyPress-Event. There the component sends the Message "WM_NextDLGCTL" 
to the parent Form. It's important to get the ParentForm, because the TMyEdit need 
not included on TForm directly but maybe on a TPanel. So you have to send the 
message directly to the parent-FORM (and not to PARENT, which may be a TPanel). 

It should be possible to use this way for other components which have a 
OnKeyPress-Event. 

1   type
2     TMyEdit = class(TEdit)
3     private
4       FEnterNextCtrl: Boolean;
5     protected
6       procedure KeyPress(var Key: Char); override;
7     published
8       property EnterNextCtrl: Boolean read FEnterNextCtrl write FEnterNextCtrl;
9       constructor Create(AOwner: TComponent); override;
10    end;
11  
12  constructor TMyEdit.Create(AOwner: TComponent);
13  begin
14    inherited;
15    FEnterNextCtrl := TRUE;
16  end;
17  
18  procedure TMyEdit.KeyPress(var Key: Char);
19  var
20    ParentForm: TCustomForm;
21  begin
22    inherited;
23    if key = #13 then
24    begin
25      Key := #0;
26  
27      //Get the parent-Form.
28      ParentForm := GetParentForm(self);
29  
30      if FEnterNextCtrl = TRUE {//Jump to next Control or beep } then
31        parentform.Perform(WM_NextDLGCTL, 0, 0)
32      else
33        messageBeep(0);
34    end;
35  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC