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

change Component

Posted on 2000-03-09
9
198 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
  • 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 100 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

860 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