Solved

change Component

Posted on 2000-03-09
9
195 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

21 Experts available now in Live!

Get 1:1 Help Now