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
Solved

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

Posted on 1998-10-25
5
154 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
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 100 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 324
How to fill array with TArray.Create? 14 95
Run video youtube webbrowse 10 65
firemonkey Android Listview Sort items 7 50
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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