这是登录窗体的单击事件
procedure TForm2.Button1Click(Sender: TObject);
var
num,user,pass,temp:string;
begin
modalresult:=mrnone;
user:=edit2.Text;
pass:=Edit3.Text;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select 用户编号 from 用户清单 where 用户名称='''+user+'''and 用户密码='''+pass+'''';
Adoquery1.Open;
temp:=adoquery1.FieldByName('用户编号').AsString;
if temp<>'' then
//如果输入了正确的用户名和密码,那么必然能查到用户编号,否则结果为空
begin
modalresult:=mrok;
form2.Hide;
end
else
begin
ShowMessage('用户名或密码错误,请检查后重新登录');
endend;project的source
begin
form2:= Tform2.Create(Application);
Application.CreateForm(TForm2, Form2);
if form2.button1.ModalResult=mrok then//如果登录成功,返回值为mrok再继续执行下边的代码,但运行是不是这样
下边的代码即使登录没成功也执行了。代码没搞懂,请老师们分析一下。
form2.hide;
form13:=tform13.Create(nil);
form13.Show;
form13.Update;
time1:=now;
repeat until time1+strtotime('00:00:1')<=now;
Application.Initialize;
application.Title:='数据管理V2.0';
Application.CreateForm(Tdm, dm);
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm17, Form17);
Application.CreateForm(TForm14, Form14);
form13.Hide;
form13.FreeOnRelease ;
Application.CreateForm(TForm10, Form10);
Application.CreateForm(TForm12, Form12);
Application.CreateForm(TForm13, Form13);
Application.Run;end.
procedure TForm2.Button1Click(Sender: TObject);
var
num,user,pass,temp:string;
begin
modalresult:=mrnone;
user:=edit2.Text;
pass:=Edit3.Text;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select 用户编号 from 用户清单 where 用户名称='''+user+'''and 用户密码='''+pass+'''';
Adoquery1.Open;
temp:=adoquery1.FieldByName('用户编号').AsString;
if temp<>'' then
//如果输入了正确的用户名和密码,那么必然能查到用户编号,否则结果为空
begin
modalresult:=mrok;
form2.Hide;
end
else
begin
ShowMessage('用户名或密码错误,请检查后重新登录');
endend;project的source
begin
form2:= Tform2.Create(Application);
Application.CreateForm(TForm2, Form2);
if form2.button1.ModalResult=mrok then//如果登录成功,返回值为mrok再继续执行下边的代码,但运行是不是这样
下边的代码即使登录没成功也执行了。代码没搞懂,请老师们分析一下。
form2.hide;
form13:=tform13.Create(nil);
form13.Show;
form13.Update;
time1:=now;
repeat until time1+strtotime('00:00:1')<=now;
Application.Initialize;
application.Title:='数据管理V2.0';
Application.CreateForm(Tdm, dm);
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm17, Form17);
Application.CreateForm(TForm14, Form14);
form13.Hide;
form13.FreeOnRelease ;
Application.CreateForm(TForm10, Form10);
Application.CreateForm(TForm12, Form12);
Application.CreateForm(TForm13, Form13);
Application.Run;end.
form2:= Tform2.Create(Application);
Application.CreateForm(TForm2, Form2);
if form2.button1.ModalResult=mrok then//如果登录成功,返回值为mrok再继续执行下边的代码,但运行是不是这样
下边的代码即使登录没成功也执行了。代码没搞懂,请老师们分析一下。
form2.hide;
改为:
form2:= Tform2.Create(Application);
if form2.ModalResult<>mrok then
begin
form2.Free;
Application.Terminate;
Exit;
end;
form2:= Tform2.Create(Application);
Application.CreateForm(TForm2, Form2);
if form2.button1.ModalResult=mrok then//如果登录成功,返回值为mrok再继续执行下边的代码,但运行是不是这样
下边的代码即使登录没成功也执行了。代码没搞懂,请老师们分析一下。
begin
form2.hide;
form13:=tform13.Create(nil);
form13.Show;
form13.Update;
time1:=now;
repeat until time1+strtotime('00:00:1')<=now;
Application.Initialize;
application.Title:='数据管理V2.0';
Application.CreateForm(Tdm, dm);
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm17, Form17);
Application.CreateForm(TForm14, Form14);
form13.Hide;
form13.FreeOnRelease ;
Application.CreateForm(TForm10, Form10);
Application.CreateForm(TForm12, Form12);
Application.CreateForm(TForm13, Form13);
Application.Run;
end;
end.
if …… then 语句,这里语句是一条语句,所以要加begin end;
Application.CreateForm(TForm2, Form2);
这样写不重复吗?
Adoquery1.Open;
temp:=adoquery1.FieldByName('用户编号').AsString;AdoQuery1.Open; 后难道不用
if AdoQuery1.IsEmpty then
begin
...
end;
测试一下吗?
赋给的是Form不是Button,你下面全部是用Button的ModalResult判断的,不会对的。
form2:= Tform2.Create(Application);
Application.CreateForm(TForm2, Form2); //这里创建了登录窗口;
if form2.button1.ModalResult=mrok then //这里的IF判断语句只影响Form2是否Hide,重点是该IF语句的作用范围。很明显,无论button1.ModalResult的值如何,程序都会继续执行form13:=tform13.Create(nil);及以下语句。
form2.hide; form13:=tform13.Create(nil);
form13.Show;