procedure TForm1.check_psw(times: integer); begin inc(times); if (loginfrm.ShowModal=mrok) then begin if (times<4) then begin if (loginfrm.Edit1.text<>'Edit1') then//此处省略了从数据库中查询用户名及密码的过程 begin application.MessageBox('没有该用户','Error',0); check_psw(times); end else if (loginfrm.Edit2.text<>'12') then begin application.MessageBox('密码错误','Error',0); check_psw(times); end else loginfrm.Free; end else begin application.MessageBox('over 3 times','error',0); application.Terminate; loginfrm.Free; end; end else begin application.MessageBox('退出程序','info',0); application.Terminate; loginfrm.Free; end; end; procedure TForm1.FormCreate(Sender: TObject); begin loginfrm:=Tloginform.Create(nil); check_psw(0); end;