我编了一个程序,可是出了一点小问题:
登录时如果用户名输入正确,则没什么问题,如果用户名输入错误的话程序提示“错误”后光标停在“用户名”,但若重新输入,不论正确错误码程序都会全部退出。

解决方案 »

  1.   

    登录界面:
    确定后如果输入错误
            showmessage('非法用户!');
              dl_mma.SetFocus;
              xt_dlu.ModalResult := mrNo;
              exit;
    确定后如果输入正确
    if mainform= nil then  //如果第一次登录
       begin
        xt_dlu.Close;
    启动程序F7
      Application.Initialize;
      Application.CreateForm(Txt_dlu, xt_dlu);
      Application.CreateForm(TDMykt, DMykt);
      Application.CreateForm(Tkq_rykqhz, kq_rykqhz);
      Application.CreateForm(TkqModule2, kqModule2);
      if xt_dlu = nil then
         xt_dlu:=txt_dlu.create(application);
      if xt_dlu.ShowModal = mrOK then
      begin
       Application.CreateForm(TmainForm, mainForm);
       mainForm.ShowModal;
       Application.Run;
      end;
       Application.Run;
        xt_dlu.ModalResult := mrOk;
        end
       else  //如果重新登录
       begin
         mainform.visible := true;
         xt_dlu.close;
       end;
      

  2.   

    在帮助文档中看到一个note,可能会有帮助:
    'If the form contains buttons with a ModalResult property set to a value other than mrNone, the form automatically closes when the user clicks one of those buttons and returns the ModalResult value as the return value of ShowModal.'