我刚学delphi我想在主窗体运行之前先通过身份验证,如通过则运行主窗体,如不通过则关闭程序,请那位大大给一完整代码,不要先将主窗体隐藏的方法!谢谢!

解决方案 »

  1.   

    可以在主窗体的OnCreate事件创建登录窗体
      

  2.   

    uses
      Forms,
      Controls,
      Unit1 in 'Unit1.pas' {Form1},
      Unit2 in 'Unit2.pas' {FrmLogin};begin
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.CreateForm(TFrmLogin, FrmLogin);
      if FrmLogin.ShowModal := mrOk then
        Application.Run;
    end.
    FrmLogin中如果登录成功,写上ModalResult := mrOk;否则写上ModalResult := mrCancel;
      

  3.   

    修改工程文件,类似如下代码
      Application.Initialize;
      FmLogin := TFmLogin.Create(Application);
      if FmLogin.ShowModal then   //ShowModal被重载,返回true/false,可以直接用 mrOK/mrCancel
      begin
        FmLogin.Free;
        Application.CreateForm(TFmMain, FmMain);
        Application.Run;
      end
      else begin
          FmLogin.Free;
      end;
      

  4.   

    我已经按take_CX和lynmison的方法去做但,老出这样的错误提示?还有谁能帮帮我呀?
      

  5.   

    我已经按take_CX和lynmison的方法去做但,老出这样的错误[Error] MDIAPP.DPR(38): Type of expression must be BOOLEAN[Error] MDIAPP.DPR(45): Statement expected but end of file found提示?以上两位大哥的方法好像无法让用户输入用户名及密码吧?我想让登录窗体等我输入用户名及密码再通过验证后运行主窗体了!还有谁能帮帮我呀?
      

  6.   

    1.改成
    if FmLogin.ShowModal=mrOK then 2.你在FrmLogin里面输入用户名密码,点击按钮验证,如果验证通过你返回mrOK
      

  7.   

    提示Debugger exception Notification的錯誤 
    內容是 project MDIApp.exe raised exception class Elnvalidoperation with message 'cannot make a visible window modal'.process stoppded uses step or run to continue 
    大哥 问题在那里?
      

  8.   


    Application.Initialize;
      FmLogin := TFmLogin.Create(Application);
      fmLogin.Visible := False;
      if FmLogin.ShowModal = mrOK then   //ShowModal被重载,返回true/false,可以直接用 mrOK/mrCancel
      begin
        FmLogin.Free;
        Application.CreateForm(TFmMain, FmMain);
        Application.Run;
      end
      else begin
          FmLogin.Free;
      end;
      

  9.   

    提示Debugger exception Notification的錯誤 
    老指示 if FmLogin.ShowModal=mrOK then 有错误!
    內容是 project MDIApp.exe raised exception class Elnvalidoperation with message 'cannot make a visible window modal'.process stoppded uses step or run to continue 
    大哥 问题在那里? 难道就没有一人回应吗?
      

  10.   

    fmLogin.Visible := False;
    这行加了没有?
      

  11.   

    在Uses后面要加上 Controls, mrOK要uses Controls
      

  12.   

    謝謝CNCHARLES還是你說的對,沒有加fmLogin.Visible := False;謝謝為什麽要加這一行呢?
      

  13.   

    Form的Visible属性默认就是False,除非你改过它的默认值