火
火鸟不死
Unregistered / Unconfirmed
GUEST, unregistred user!
我做的是一个简单的学生姓名与学号的查询系统。
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Label3: TLabel;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
DataSource1: TDataSource;
Table1: TTable;
procedure Edit1enter(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1Enter(Sender: TObject);
begin
edit1.Text:=''; //清空edit1
edit2.Text:=''; //清空edit2
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with table1 do
begin
label3.Caption:='';
indexfieldnames:='sn';
setkey;
if edit1.text=''then
showmessage('请输入查询学号')
ELSE
fieldbyname('sn').asstring:=edit1.text;
if gotokey then
begin
label3.caption:='查询成功';
edit2.Text:=fieldbyname('name').AsString;
memo1.Lines[0]:='姓名:'+fieldbyname('name').asstring;
memo1.Lines[1]:='学号:'+fieldbyname('sn').asstring;
end
else
begin
edit2.Text:='查询此人不在';
label3.caption:='查找失败';
memo1.Lines[0]:='此人不在';
memo1.lines[1]:='';
end;
end;
end;
运行之后在edit1中不能输入任何东西,edit2中却可以。请问这里有什么毛病啊?应该怎么
改啊?谢谢!
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Label3: TLabel;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
DataSource1: TDataSource;
Table1: TTable;
procedure Edit1enter(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Edit1Enter(Sender: TObject);
begin
edit1.Text:=''; //清空edit1
edit2.Text:=''; //清空edit2
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
with table1 do
begin
label3.Caption:='';
indexfieldnames:='sn';
setkey;
if edit1.text=''then
showmessage('请输入查询学号')
ELSE
fieldbyname('sn').asstring:=edit1.text;
if gotokey then
begin
label3.caption:='查询成功';
edit2.Text:=fieldbyname('name').AsString;
memo1.Lines[0]:='姓名:'+fieldbyname('name').asstring;
memo1.Lines[1]:='学号:'+fieldbyname('sn').asstring;
end
else
begin
edit2.Text:='查询此人不在';
label3.caption:='查找失败';
memo1.Lines[0]:='此人不在';
memo1.lines[1]:='';
end;
end;
end;
运行之后在edit1中不能输入任何东西,edit2中却可以。请问这里有什么毛病啊?应该怎么
改啊?谢谢!