Solved

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

Posted on 1998-10-25
5
152 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
  • 3
5 Comments
 
LVL 4

Expert Comment

by:dwwang
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 100 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

12 Experts available now in Live!

Get 1:1 Help Now