Solved

change Component

Posted on 2000-03-09
9
194 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:hypereng
Comment Utility
You might use

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

Expert Comment

by:Lischke
Comment Utility
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
Comment Utility
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
Comment Utility
To Lishke,
sorry, but it will work if edits are placed on panel too.
0
 
LVL 9

Expert Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

14 Experts available now in Live!

Get 1:1 Help Now