?
Solved

How to use the keys DOWN, UP and ENTER in the same way that in Clipper?

Posted on 1998-10-25
5
Medium Priority
?
158 Views
Last Modified: 2010-04-06
How to use the keys DOWN, UP and ENTER in the same way that in Clipper?  
 
In a program done in Clipper, same when he is publishing a field, the key DOWN it is going to the next field; the key UP is going to the previous field and the key ENTER it works like TAB (it is also going to the next field).  
Please show a routine that makes this.  
 
Thank you  
 
Gaona
0
Comment
Question by:gaona
[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
5 Comments
 
LVL 4

Expert Comment

by:dwwang
ID: 1344295
Write some code in the OnKeyPress/OnKeydown event of the components:

procedure Tmyform.edit1keypress(Sender: TObject; var Key: Char);
begin
     if Key=#13 then      //Enter pressed
        begin
        key:=#0;
        SelectNext(Sender as TWinControl,True,True);
        end;
end;

up/down can be processed similarly.
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344296
gaona

dwwang is totllay correct but if it's in a dbgrid as I see you are referenceing to field etc. the code needs to change here is a simple example

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);

{ You should also set the Form's KeyPreview property to True }

begin
  if Key = #13 then                              
    if not (ActiveControl is TDBGrid) then begin
      Key := #0;                                
      Perform(WM_NEXTDLGCTL, 0, 0);              
    end
    else if (ActiveControl is TDBGrid) then      
      with TDBGrid(ActiveControl) do
        if selectedindex < (fieldcount -1) then  
          selectedindex := selectedindex +1
        else
          selectedindex := 0;
end;

for the up down stuff

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);

{ You should also set the Form's KeyPreview property to True }

begin
  if Key = VK_DOWN then                              
    if not (ActiveControl is TDBGrid) then begin
      Key := #0;                                
      Perform(WM_NEXTDLGCTL, 0, 0);              
    end
    else if (ActiveControl is TDBGrid) then      
      with TDBGrid(ActiveControl) do
        if selectedindex < (fieldcount -1) then  
          selectedindex := selectedindex +1
        else
          selectedindex := 0;
end;

Etc.

Later
BoRiS
0
 

Author Comment

by:gaona
ID: 1344297
Dear Boris and  Dwwang
 
Its answer works partially. I suppose that I should also test the keys VK_UP and VK_DOWN to go to the previous field and the next field. Even so, I have three problems:  
 - The property alone OnKeyPress not accepts the change of behavior of the keys UP and DOWN when I am publishing the field.  
- To use the property OnKeyDown, I will have to redraft the same function, and even so, the key UP won't be recognized.  
- In a DBGrid, when I press DOWN or UP, it would like that the focus of the table, passed for the first field of DBGrid and not for the next field as it happens.  
 
Thankful  
 
Gaona
0
 
LVL 4

Expert Comment

by:dwwang
ID: 1344298
Would you give some mre details why it doew not work?

By the way, onkeypress and onkeydown are different, one treat key as a char and another treat it as Integer.

and for not to define onkeypress for every control, you can write a event procedure:

procedure keyprocess(sender: tobject; var key :char);
begin
     if key=#13 then ...
     if key=#(UP key character value) then ....
end;

Put this procedure among those event hanlers and then
in the property editer point the OnkeyPress event to this
procedure;
0
 
LVL 4

Accepted Solution

by:
dwwang earned 200 total points
ID: 1344299
Our softwares also do those processes, so if you meet any problem, just describe it in more details, or paste some of your code here.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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