Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

change Component

Posted on 2000-03-09
9
Medium Priority
?
203 Views
Last Modified: 2010-04-04
I have four Dbedit Component, and I want change but not press Tab, I want press Enter for change to Dbedit2 ...an after Dbedit3 ..etc
0
Comment
Question by:chiro
[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
  • 2
  • 2
  • +2
9 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 2600401
at OnKeyPress event of DBEdit1 write this code:

 if Key = #13 then
  dbEdit2.Setfocus;

on OnKeypress on dbEdit2 write

 if Key = #13 then
  dbEdit3.Setfocus;

Motaz
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2600434
Hi again Chiro,

let me help you on this question too :-) I recommend that you assign an event handler to each of the edits for the OnKeyPress event and use the TWinControl.SelectNext method to select the next control in tab order. You need a little dirty trick to get access to the as protected declared method, but you have then a universal handler:

type
  TMyWinControl = class(TWinControl)
  end;
 
procedure TMainForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if (Key = #13) and
     (Sender is TWinControl) and
     Assigned(TWinControl(Sender).Parent) then
  begin
    TMyWinControl(TWinControl(Sender).Parent).SelectNext(Sender as TWinControl, True, True);
    Key := #0;
  end;
end;


Ciao, Mike
0
 
LVL 9

Accepted Solution

by:
ITugay earned 400 total points
ID: 2600444
Just set Form1.KeyPreview property to true, and write Form1.OnKeyDown method.

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);
begin
  case Key of
  vk_Return :  begin
                          SelectNext(ActiveControl,true,true);
                          Key:=0;
                      end;  
...... skipped .....
  end;
end;

Every time, you will press [Enter] next component on form will be selected, not only DBEdit.

Cheers,
Igor
0
Industry Leaders: 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!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 2600452
hi chiro,

you can do a descandent of Tdbedit
and override the keDown Method like

procedure TOtherDBEdit.KeyDown(var Key: Word; Shift: TShiftState);
Begin
  inherited;
  If Key = VK_RETURN then
    If (Owner is TWinControl) then
       PostMessage(TWinControl(Owner).Handle,WM_NEXTDLGCTL,0,0);
End;

meikl
0
 

Expert Comment

by:hypereng
ID: 2600454
You might use

if key = #13 then
begin
  key := #0;
  dbEdit2.SetFocus
end;
 
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2600483
Igor, and what happend when the edits are placed on a panel? PLEASE, don't answer questions if there's already a discussion underway unless you are very, very sure you have the ultimate solution which nobody else has already mentioned.

Ciao, Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2600488
just done,

unit OtherDBEdit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Mask, DBCtrls;

type
  TOtherDBEdit = class(TDBEdit)
  private
    { Private declarations }
  protected
    { Protected declarations }
    Procedure KeyDown(var Key: Word; Shift: TShiftState); Override;
  public
    { Public declarations }
  published
    { Published declarations }
  end;

procedure Register;

implementation

Procedure TOtherDBEdit.KeyDown(var Key: Word; Shift: TShiftState);
Begin
  inherited;
  If Key = VK_RETURN then
    If (Owner is TWinControl) then
       PostMessage(TWinControl(Owner).Handle,WM_NEXTDLGCTL,0,0);
End;

procedure Register;
begin
  RegisterComponents('Samples', [TOtherDBEdit]);
end;

end.

meikl
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2600505
To Lishke,
sorry, but it will work if edits are placed on panel too.
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2600519
To Lishke,
sorry, but it will work if edits are placed on panel too.
0

Featured Post

Industry Leaders: 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

688 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