看看我的程序为何不运行了
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
procedure FormCreate(Sender:TObject);
procedure Edit1Exit(Sender:TObject);
procedure Button1Click(Sender:TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender:TObject);
begin
Form1.Edit1.Text:='';
Form1.ListBox1.Clear();
Form1.Button1.Enabled:=false;
end;procedure TForm1.Edit1Exit(Sender:TObject);
begin
if(Form1.Edit1.Text='') then
begin
Showmessage('请输入学号');
Form1.Edit1.SetFocus();
Form1.Button1.Enabled:=false;
exit;
end;
if(StrToInt(Form1.Edit1.Text)<0) then
begin
Showmessage('输入的学号不正确');
Form1.Edit1.SetFocus();
Form1.Button1.Enabled:=false;
exit;
end;
Form1.Button1.Enabled:=true;
end;procedure TForm1.Button1Click(Sender:TObject);
var
xuehao:integer;
begin
xuehao:=StrToInt(Form1.Edit1.Text);
Form1.ListBox1.Clear();
case xuehao of
950255:
begin
Form1.ListBox1.Items.Add('姓名:刘志');
Form1.ListBox1.Items.Add('年龄:19');
Form1.ListBox1.Items.Add('性别:男');
Form1.ListBox1.Items.Add('院系:大连理工大学');
Form1.ListBox1.Items.Add('备注:辽宁人,性格豪爽');
exit;
end;
else
begin
Showmessage('没有找到此学生信息');
end;
end;
end;
end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
ListBox1: TListBox;
procedure FormCreate(Sender:TObject);
procedure Edit1Exit(Sender:TObject);
procedure Button1Click(Sender:TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender:TObject);
begin
Form1.Edit1.Text:='';
Form1.ListBox1.Clear();
Form1.Button1.Enabled:=false;
end;procedure TForm1.Edit1Exit(Sender:TObject);
begin
if(Form1.Edit1.Text='') then
begin
Showmessage('请输入学号');
Form1.Edit1.SetFocus();
Form1.Button1.Enabled:=false;
exit;
end;
if(StrToInt(Form1.Edit1.Text)<0) then
begin
Showmessage('输入的学号不正确');
Form1.Edit1.SetFocus();
Form1.Button1.Enabled:=false;
exit;
end;
Form1.Button1.Enabled:=true;
end;procedure TForm1.Button1Click(Sender:TObject);
var
xuehao:integer;
begin
xuehao:=StrToInt(Form1.Edit1.Text);
Form1.ListBox1.Clear();
case xuehao of
950255:
begin
Form1.ListBox1.Items.Add('姓名:刘志');
Form1.ListBox1.Items.Add('年龄:19');
Form1.ListBox1.Items.Add('性别:男');
Form1.ListBox1.Items.Add('院系:大连理工大学');
Form1.ListBox1.Items.Add('备注:辽宁人,性格豪爽');
exit;
end;
else
begin
Showmessage('没有找到此学生信息');
end;
end;
end;
end.
begin
if(Form1.Edit1.Text='') then
begin
Showmessage('请输入学号');
Form1.Edit1.SetFocus();
Form1.Button1.Enabled:=false;
exit;
end;
if(StrToInt(Form1.Edit1.Text)<0) then
begin
Showmessage('输入的学号不正确');
Form1.Edit1.SetFocus();
Form1.Button1.Enabled:=false;
exit;
end;
Form1.Button1.Enabled:=true;
end;
你的程序可以运行,关键是你没搞清楚Exit事件。你输入了学号后,点一下ListBox,就运行了。
这个事件似乎用不恰当,你要用这个事件来表示什么,判断吗。
你应该用onkey事件好一点吧。当按回车的时候判断