Solved

change Component

Posted on 2000-03-09
9
199 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 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
Independent Software Vendors: 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

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

Suggested Solutions

Title # Comments Views Activity
Delphi 2 77
Convert GUI app into console app for Win32 Env 5 125
Delphi: ForceDirectory plain function 7 50
Sending files from  idTcpServer Socket to idTcpClient 2 52
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

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