unit loginpas;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, DB, DBClient, MConnect, Grids, DBGrids, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, ComCtrls;type Tlogin = class(TForm) Image1: TImage; Edit1: TEdit; Label1: TLabel; Label2: TLabel; Edit2: TEdit; BitBtn1: TBitBtn; BitBtn2: TBitBtn; Label3: TLabel; Label4: TLabel; Edit3: TEdit; Edit4: TEdit; zcdTCP: TIdTCPClient; StatusBar1: TStatusBar; procedure BitBtn1Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); procedure FormActivate(Sender: TObject); procedure Edit1Exit(Sender: TObject); procedure FormKeyPress(Sender: TObject; var Key: Char); procedure Edit2Change(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); private { Private declarations } ServerDown: Boolean; ClientNo: string; public { Public declarations } gonghao_,passwor,bumeng_,xingming_,quanxian_,dnbh_:string; state:int64; sfslkl:boolean; end;var login: Tlogin;implementationuses flashpas,maindata, jxbzcd;{$R *.dfm}procedure Tlogin.BitBtn1Click(Sender: TObject); begin if sfslkl then begin if trim(passwor)<>trim(edit2.Text) then begin ShowMessage('口令错误,请重新输入!'); edit2.SetFocus; end else begin login.Hide ; mainModule1.operatorClient.Close ; Application.CreateForm(Tzcd, zcd); zcd:=tzcd.Create(application); zcd.ShowModal ; login.Close; end; end else begin ShowMessage('没有输入口令!'); edit1.SetFocus ; end; end;procedure Tlogin.BitBtn2Click(Sender: TObject); begin close; end;procedure Tlogin.FormActivate(Sender: TObject); var currentTime:LongInt; begin currentTime:=(GetTickCount div 1000); while ((GetTickCount div 1000)<(currentTime+3)) do ; try // Connect to server with zcdTCP do begin Host:= 'leijinhe'; Connect; // Read ID-no Writeln('用户正在登陆...'); ClientNo:= Readln('', 3000); // Timeout 3 secs if ClientNo = 'Server full' then begin MessageDlg('连接用户已满200个. ' + #13#10 + '请在其它时间登陆 !', mtWarning, [mbOK], 0); end else if ClientNo = '' then begin StatusBar1.SimpleText:= '新用户被拒绝...'; end else begin // Connection accepted by server. ServerDown:= false; StatusBar1.SimpleText:= '新用户已连接...'; end; end; except on E: Exception do begin StatusBar1.SimpleText:= '新用户未连上...'; end; end;end;procedure Tlogin.Edit1Exit(Sender: TObject); const ssql:string='select * from operator where gonghao='; var sselect:string; begin sfslkl:=false; if not mainModule1.DCOM.Connected then mainModule1.DCOM.Connected:=true; sselect:=ssql+''''+edit1.Text+''''+'' ; mainModule1.operatorClient.Close ; mainModule1.operatorClient.CommandText:=sselect; mainModule1.operatorClient.Open; if not mainModule1.operatorClient.IsEmpty then begin edit3.Text:=trim(mainModule1.operatorClient.FieldValues['bumeng']); bumeng_:=edit3.Text ; edit4.Text:=trim(mainModule1.operatorClient.FieldValues['xingming']); xingming_:=edit4.Text ; passwor:=mainModule1.operatorClient.FieldValues['password']; quanxian_:=trim(mainModule1.operatorClient.FieldValues['authority']); dnbh_:=trim(mainModule1.operatorClient.FieldValues['dnbianhao']); gonghao_:=trim(mainModule1.operatorClient.FieldValues['gonghao']); end else begin ShowMessage('无此人工号!'); edit1.SetFocus ; end; end;procedure Tlogin.FormKeyPress(Sender: TObject; var Key: Char); begin if key = #13 then begin key := #0; PerForm(WM_NEXTDLGCTL,0,0); end;end; procedure Tlogin.Edit2Change(Sender: TObject); begin sfslkl:=true; end;procedure Tlogin.FormClose(Sender: TObject; var Action: TCloseAction); begin if not ServerDown then with zcdTCP do begin Writeln(login.gonghao_+'用户离开...'); Disconnect; end; Action:= caFree;end;procedure Tlogin.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=13 then begin PerForm(WM_NextDlgCtl,0,0); end; end;end.
type TMYGrid = class(TCustomGrid); TMYDBGrid = class(TCustomDBGrid); TCustomMISForm = class(TForm) procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormKeyPress(Sender: TObject; var Key: Char); private procedure TabToEnter(var Key: Word; Shift: TShiftState); protected FKey: Word; FShift: TShiftState; public end;var CustomMISForm: TCustomMISForm;implementation{$R *.dfm}procedure TCustomMISForm.TabToEnter(var Key: Word; Shift: TShiftState); begin if Key = VK_Return then begin Key := 0; if ((ActiveControl is TCustomGrid) or (ActiveControl.Parent is TCustomGrid)) then begin Key := VK_TAB; TMYGrid(ActiveControl as TCustomGrid).KeyDown(Key, Shift); end else Perform(CM_DIALOGKey, VK_TAB, 0); end; end;procedure TCustomMISForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin FKey := KEy; FShift := Shift; end;procedure TCustomMISForm.FormKeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then begin Key := #0; TabToEnter(FKey, FShift); end; end;end.
key=vk_tab
SelectNext(ActiveControl,True,True);
if key = #13 then
begin
key := #0;
PerForm(WM_NEXTDLGCTL,0,0);
end;
然后在formKeyDown事件中写如下代码:
if key=13 then
begin
PerForm(WM_NextDlgCtl,0,0);
end;
XP比较拽...一定要加入PERFORM之类的消息广播
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, DB, DBClient, MConnect, Grids,
DBGrids, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
ComCtrls;type
Tlogin = class(TForm)
Image1: TImage;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Label3: TLabel;
Label4: TLabel;
Edit3: TEdit;
Edit4: TEdit;
zcdTCP: TIdTCPClient;
StatusBar1: TStatusBar;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Edit1Exit(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Edit2Change(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
ServerDown: Boolean;
ClientNo: string;
public
{ Public declarations }
gonghao_,passwor,bumeng_,xingming_,quanxian_,dnbh_:string;
state:int64;
sfslkl:boolean;
end;var
login: Tlogin;implementationuses flashpas,maindata, jxbzcd;{$R *.dfm}procedure Tlogin.BitBtn1Click(Sender: TObject);
begin
if sfslkl then
begin
if trim(passwor)<>trim(edit2.Text) then
begin
ShowMessage('口令错误,请重新输入!');
edit2.SetFocus;
end
else
begin
login.Hide ;
mainModule1.operatorClient.Close ;
Application.CreateForm(Tzcd, zcd);
zcd:=tzcd.Create(application);
zcd.ShowModal ;
login.Close;
end;
end
else
begin
ShowMessage('没有输入口令!');
edit1.SetFocus ;
end;
end;procedure Tlogin.BitBtn2Click(Sender: TObject);
begin
close;
end;procedure Tlogin.FormActivate(Sender: TObject);
var
currentTime:LongInt;
begin
currentTime:=(GetTickCount div 1000);
while ((GetTickCount div 1000)<(currentTime+3)) do ;
try
// Connect to server
with zcdTCP do
begin
Host:= 'leijinhe';
Connect;
// Read ID-no
Writeln('用户正在登陆...');
ClientNo:= Readln('', 3000); // Timeout 3 secs
if ClientNo = 'Server full' then
begin
MessageDlg('连接用户已满200个. ' + #13#10 +
'请在其它时间登陆 !', mtWarning, [mbOK], 0);
end
else
if ClientNo = '' then
begin
StatusBar1.SimpleText:= '新用户被拒绝...';
end
else
begin
// Connection accepted by server.
ServerDown:= false;
StatusBar1.SimpleText:= '新用户已连接...';
end;
end;
except
on E: Exception do
begin
StatusBar1.SimpleText:= '新用户未连上...';
end;
end;end;procedure Tlogin.Edit1Exit(Sender: TObject);
const
ssql:string='select * from operator where gonghao=';
var
sselect:string;
begin
sfslkl:=false;
if not mainModule1.DCOM.Connected then mainModule1.DCOM.Connected:=true;
sselect:=ssql+''''+edit1.Text+''''+'' ;
mainModule1.operatorClient.Close ;
mainModule1.operatorClient.CommandText:=sselect;
mainModule1.operatorClient.Open;
if not mainModule1.operatorClient.IsEmpty then
begin
edit3.Text:=trim(mainModule1.operatorClient.FieldValues['bumeng']);
bumeng_:=edit3.Text ;
edit4.Text:=trim(mainModule1.operatorClient.FieldValues['xingming']);
xingming_:=edit4.Text ;
passwor:=mainModule1.operatorClient.FieldValues['password'];
quanxian_:=trim(mainModule1.operatorClient.FieldValues['authority']);
dnbh_:=trim(mainModule1.operatorClient.FieldValues['dnbianhao']);
gonghao_:=trim(mainModule1.operatorClient.FieldValues['gonghao']);
end
else
begin
ShowMessage('无此人工号!');
edit1.SetFocus ;
end;
end;procedure Tlogin.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
begin
key := #0;
PerForm(WM_NEXTDLGCTL,0,0);
end;end;
procedure Tlogin.Edit2Change(Sender: TObject);
begin
sfslkl:=true;
end;procedure Tlogin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if not ServerDown then
with zcdTCP do
begin
Writeln(login.gonghao_+'用户离开...');
Disconnect;
end;
Action:= caFree;end;procedure Tlogin.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=13 then
begin
PerForm(WM_NextDlgCtl,0,0);
end;
end;end.
TMYGrid = class(TCustomGrid);
TMYDBGrid = class(TCustomDBGrid); TCustomMISForm = class(TForm) procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormKeyPress(Sender: TObject; var Key: Char); private
procedure TabToEnter(var Key: Word; Shift: TShiftState); protected
FKey: Word;
FShift: TShiftState;
public end;var
CustomMISForm: TCustomMISForm;implementation{$R *.dfm}procedure TCustomMISForm.TabToEnter(var Key: Word;
Shift: TShiftState);
begin
if Key = VK_Return then
begin
Key := 0;
if ((ActiveControl is TCustomGrid) or (ActiveControl.Parent is TCustomGrid)) then
begin
Key := VK_TAB;
TMYGrid(ActiveControl as TCustomGrid).KeyDown(Key, Shift);
end else
Perform(CM_DIALOGKey, VK_TAB, 0);
end;
end;procedure TCustomMISForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
FKey := KEy;
FShift := Shift;
end;procedure TCustomMISForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
Key := #0;
TabToEnter(FKey, FShift);
end;
end;end.
把第三个参数换一个试试
Keybd_Event(vk_Tab,0,Keyeventf_ExtendedKey,0);
我也这样用的