你不会是在FORM的KeyPress中用了 if key=#13 then key=#0; (前提:Form.KeyPreview:=true)
我想一定是Edit2KeyPress事件上面的程序出了问题!你仔细找找错误吧!
to:cobi(我是小新) edit控件所在的窗体的keypreview是false; to:liang_z(千山一刀之忍者神龟) 偶可没用什么key=#0喔. 还有就是偶的程序上面没有任何涉及到keypress的(在本窗体中),我好象记得这个事件会被什么事件给覆盖的吧,但偶又想不出,麻烦各位了. 本窗体程序为: unit setpasswd;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Buttons;type TForm33 = class(TForm) Label1: TLabel; GroupBox1: TGroupBox; BitBtn1: TBitBtn; BitBtn2: TBitBtn; Edit2: TEdit; Label2: TLabel; Label3: TLabel; ComboBox1: TComboBox; BitBtn3: TBitBtn; Panel1: TPanel; Label4: TLabel; ComboBox2: TComboBox; Label5: TLabel; Label6: TLabel; Edit1: TEdit; Label7: TLabel; Edit3: TEdit; Label8: TLabel; Edit4: TEdit; BitBtn4: TBitBtn; BitBtn5: TBitBtn; BitBtn6: TBitBtn; procedure FormCreate(Sender: TObject); procedure ComboBox1DropDown(Sender: TObject); procedure ComboBox1Change(Sender: TObject); procedure Edit2KeyPress(Sender: TObject; var Key: Char); procedure ComboBox2DropDown(Sender: TObject); procedure ComboBox2Change(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form33: TForm33;implementationuses datamodule;{$R *.dfm}procedure TForm33.FormCreate(Sender: TObject); begin datamodule1.adoquery12.close; end;procedure TForm33.ComboBox1DropDown(Sender: TObject); var i,m:integer; begin combobox1.Items.Clear; with datamodule1.adoquery12 do begin Close; SQL.Clear; SQL.add('select * from 用户'); open; while not Eof do begin for i:=0 to combobox1.Items.Count do begin if combobox1.Items.Strings[i]=fieldbyname('用户名').asstring then begin m:=1; end; end; if m<>1 then ComboBox1.Items.Add(fieldbyname('用户名').asstring); Next; end; end; datamodule1.ADOQuery12.Close; end;procedure TForm33.ComboBox1Change(Sender: TObject); begin edit2.SetFocus; with datamodule1.adoquery12 do begin close; sql.clear; sql.add('select * from 用户'); sql.add('where 用户名='''+trim(combobox1.Text)+''''); open; end; end; ************************************************************ procedure TForm33.Edit2KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then bitbtn1.Enabled:=true; end; ************************************************************* procedure TForm33.ComboBox2DropDown(Sender: TObject); var i,m:integer; begin combobox1.Items.Clear; with datamodule1.adoquery12 do begin Close; SQL.Clear; SQL.add('select * from 用户'); open; while not Eof do begin for i:=0 to combobox1.Items.Count do begin if combobox1.Items.Strings[i]=fieldbyname('权限').asstring then begin m:=1; end; end; if m<>1 then ComboBox1.Items.Add(fieldbyname('权限').asstring); Next; end; end; datamodule1.ADOQuery12.Close; end; 还没有完全结束呢
if key=#13 then
key=#0;
(前提:Form.KeyPreview:=true)
edit控件所在的窗体的keypreview是false;
to:liang_z(千山一刀之忍者神龟)
偶可没用什么key=#0喔.
还有就是偶的程序上面没有任何涉及到keypress的(在本窗体中),我好象记得这个事件会被什么事件给覆盖的吧,但偶又想不出,麻烦各位了.
本窗体程序为:
unit setpasswd;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;type
TForm33 = class(TForm)
Label1: TLabel;
GroupBox1: TGroupBox;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Edit2: TEdit;
Label2: TLabel;
Label3: TLabel;
ComboBox1: TComboBox;
BitBtn3: TBitBtn;
Panel1: TPanel;
Label4: TLabel;
ComboBox2: TComboBox;
Label5: TLabel;
Label6: TLabel;
Edit1: TEdit;
Label7: TLabel;
Edit3: TEdit;
Label8: TLabel;
Edit4: TEdit;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure ComboBox1DropDown(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure ComboBox2DropDown(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form33: TForm33;implementationuses datamodule;{$R *.dfm}procedure TForm33.FormCreate(Sender: TObject);
begin
datamodule1.adoquery12.close;
end;procedure TForm33.ComboBox1DropDown(Sender: TObject);
var
i,m:integer;
begin
combobox1.Items.Clear;
with datamodule1.adoquery12 do
begin
Close;
SQL.Clear;
SQL.add('select * from 用户');
open;
while not Eof do
begin
for i:=0 to combobox1.Items.Count do
begin
if combobox1.Items.Strings[i]=fieldbyname('用户名').asstring then
begin
m:=1;
end;
end;
if m<>1 then
ComboBox1.Items.Add(fieldbyname('用户名').asstring);
Next;
end;
end;
datamodule1.ADOQuery12.Close;
end;procedure TForm33.ComboBox1Change(Sender: TObject);
begin
edit2.SetFocus;
with datamodule1.adoquery12 do
begin
close;
sql.clear;
sql.add('select * from 用户');
sql.add('where 用户名='''+trim(combobox1.Text)+'''');
open;
end;
end;
************************************************************
procedure TForm33.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
bitbtn1.Enabled:=true;
end;
*************************************************************
procedure TForm33.ComboBox2DropDown(Sender: TObject);
var
i,m:integer;
begin
combobox1.Items.Clear;
with datamodule1.adoquery12 do
begin
Close;
SQL.Clear;
SQL.add('select * from 用户');
open;
while not Eof do
begin
for i:=0 to combobox1.Items.Count do
begin
if combobox1.Items.Strings[i]=fieldbyname('权限').asstring then
begin
m:=1;
end;
end;
if m<>1 then
ComboBox1.Items.Add(fieldbyname('权限').asstring);
Next;
end;
end;
datamodule1.ADOQuery12.Close;
end;
还没有完全结束呢
你说的情况实在和我太一样了,偶就是这样,不只现在了,偶实在无法忍受了,以前偶只能用其它事件来代替,唉,受不了,现在来求助于各位,望能想个好方法.