Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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