现在我做的是个登陆窗口,进行验证登陆。我把好多初始化的工作都在登陆窗口的“确定”按钮中做了,如果输入的密码三次了,然后就应用程序终止,可是应用程序,并没有终止掉!
program project;
uses
  
begin
  CreateMutex(nil, false, 'project');
  创建多个窗体;
  loginFrm.showmodal;   //在这以后,就交给登陆窗体的OK按钮来做事了,进行初始化等
  end;
----------------
unit login
uses
。。
procedure btnOKClick(sender :tobject)
begin
  if loginCount<4 then
  begin  
    在数据库查询,是否正确;
    if 正确 then 初始化;
    else
    if loginCount=3 then  application.terminate;
    else   
      showmessage('输入三次机会,现已'+IntToStr(loginCount)+'次');
  end;
  if 
end。
 就是上面的application.terminate;不能终止掉程序,可能是一些资源没释放掉,不知道怎么搞更好些,还有在login窗体里搞这些东西,是不是不好?急!!

解决方案 »

  1.   

    首先看看你的loginCount是否在每次输错密码后加1了
    然后,你这个地方不需要application.terminate,只需要根据密码的正误来决定modalresult,然后在工程文件中根据showmodal返回的结果来决定是继续程序,还是中止。
      

  2.   

    ReleaseMutex(hMutex); // release the mutex as a politeness
         CloseHandle(hMutex); // close the mutex handle
      

  3.   

    在哪儿也没有看到你把loginCount的值加了1......估计你的loginCount会永远是0或是1,不知道你初化时loginCount是多少呢?代码里头用个这个做什么呢?
    if loginCount=3 then  application.terminate;//--如果用了这个,前面的if loginCount<4 then 就不用了var
      logincount:byte=0;
      
    procedure btnOKClick(sender :tobject)
    begin
    在数据库查询,是否正确;
    if 正确 then
    begin   
      初始化;
      loginsuccess=true;
      modalreslut:=mrok;
    end
        else
     begin
          inc(logincount);
          if logincount=3 then
           begin
              showmessage('登录失败!');
              modalresult:=mrcancle;
           end
          else
         
           showmessage('输入三次机会,现已'+IntToStr(loginCount)+'次');
      end;
     
      

  4.   

    if 正确 then
    begin   
      初始化;
      loginsuccess=true;
      modalreslut:=mrok;
    end其实最初的时候,我就是不知道modalreslut:=mrok;才把所有的初始化代码写到确认按钮的,知道这个我就可以,在应用程序中调用返回值啦
      

  5.   

    还有哦,在delphi工具条上“RUN”-->"Parameters",这个窗口在调试的时候,怎么使用?谢谢:)
      

  6.   

    最简写法,想中止程序,调用 Halt;
      

  7.   

    你这样
    if loginFrm.showmodal<>mrOk then 
    begin
          application.terminate;//
    end;
      

  8.   

    hehe...
    计数还是要在LoginFrm里面完成的,如果超过三次失败或者取消登陆那么就返回mrCancel否则如果登陆成功就返回mrOk,在project中根据返回值决定是Terminate还是进行数据的初始化...
    这是比较正统的思路...
      

  9.   

    我现在问的问题是这个:
    在delphi工具条上“RUN”-->"Parameters",这个窗口在调试的时候,怎么使用?谢谢:)