花了一个星期的时间,天天冥思苦想,反复尝试,终于找到一种比较完美的方法,贴出来和大家共享:<br><br>procedure TForm4.FormCreate(Sender: TObject);<br>....<br> <br>begin<br><br> .......<br> adoconnection1.Close;<br><br> login:=Tlogin.Create(self);<br> login.ShowModal;<br> <br> 运行菜单;<br> <br> end;<br><br><br>procedure Tlogin.Button1Click(Sender: TObject);<br>var<br> cmdstr,password:string;<br> <br>begin<br> trtm:=trtm+1;<br> try<br> if (trtm<=4) then<br> begin<br> user_id:=trim(login.edit1.Text);<br> password:=trim(copy(login.edit2.text,1,6));<br><br> adoconnection1.close;<br> cmdstr:= ' use xm select user_id,password,username from userrights ';<br> cmdstr:=cmdstr+' where ltrim(rtrim(user_id))='+''''+trim(user_id)+'''';<br> cmdstr:=cmdstr+' and ltrim(rtrim(password))='+''''+trim(password)+'''';<br> adodataset1.CommandText:=cmdstr;<br> adodataset1.Open;<br><br> if (adodataset1.EOF) then<br> begin<br> application.MessageBox('你的输入不正确!',' 错误',IDOK);<br> if(trtm<4)then<br> begin<br> login.close;<br> login:=Tlogin.Create(self);<br> login.ShowModal;<br> //login.Edit1.Text:='';<br> //login.Edit2.Text:='';<br> //login.Edit1.SetFocus;<br> //exit;<br> end<br> else<br> application.Terminate;<br> end<br> else<br> begin<br> Form4.Statusbar1.Panels[0].Text:='营业部';<br> Form4.Statusbar1.Panels[2].Text:=adodataset1.FieldValues['user_id'];<br> Form4.Statusbar1.Panels[3].Text:=adodataset1.FieldValues['username'];<br> end;<br> end<br> else<br> begin<br> application.Terminate;<br> end;<br> finally<br> login.Close;<br> end;<br>end;