You can find the ans. from www.delphi32.com

解决方案 »

  1.   

    在工程文件的begin...end.之间啊!
    begin
      Application.Initialize;
      Application.Title := '应用程序标题';
      FrmUserLogin:=TFrmUserLogin.Create(nil);
      FrmUserLogin:=TFrmUserLogin.Create(nil);//密码验证窗体  
      try
        FrmUserlogin.ShowModal ;
        if FrmUserlogin.LoginValue = True then//验证成功
        begin
          Application.CreateForm(TFrmMainUnit, FrmMainUnit);
          Application.Run;
        end;
      finally
        FrmUserlogin.Free;
      end;
    end.
      

  2.   

    也可以在 Mainform onshow过程中启动 登陆窗体
      

  3.   

    public
        Passed;Boolean;{A flag to determine user passed login or not} 
      end;
    var
      Form1:TForm1;
      
    implementprocedure TForm1.FormCreate(Sender:TObject);
    begin
      Passed:=False;
    end;procedure TForm1.FormShow(Sender:TObject);
    begin
      if Not Passed then
      begin
        LoginForm:=TLoginForm.Create(Self);
        LoginForm.ShowModal;
        LoginForm.Free;
      end;
    end;以下是LoginForm的登陆窗口中点击确定按钮的事件:
    uses unit1;procedure TLoginForm.Button1Click(Sender:TObject)
    begin
      {check the ID and Password of a user} 
      if 通过 then
        Form1.Passed:=True
      else
        Form1.Passed:=False; 
    end;
      

  4.   

    先建一个登陆窗体然后在工程的dpr文件里删除它的create代码,在主窗体的create事件里写下列代码。(我的登陆窗体为formflash)
       formflash:=Tformflash.Create(application);
       formflash.showmodal;
       formflash.Update;
      

  5.   

    你将登录窗体作为主窗体,登录成功后显示主窗体,隐藏登录窗体,代码如下:unit LoginUnit;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Buttons, DB, DBTables, wwdbdatetimepicker;type
      Tlogin = class(TForm)
        GroupBox1: TGroupBox;
        edtUser: TEdit;
        edtPswd: TEdit;
        lblUser: TLabel;
        lblPassword: TLabel;
        bbtnOK: TBitBtn;
        bbtnCancel: TBitBtn;
        procedure bbtnCancelClick(Sender: TObject);
        procedure bbtnOKClick(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      login: Tlogin;implementationuses MainForm, MastData;{$R *.DFM}procedure Tlogin.bbtnCancelClick(Sender: TObject);
    begin
      Application.Terminate;
    end;procedure Tlogin.bbtnOKClick(Sender: TObject);
    begin
      with MastData.ADOData do
      begin     
        try
          T_user.Filter:='ID='''+edtUser.Text+'''';
          T_user.Filtered:=True; 
          T_user.Open;
        except
          Application.MessageBox('请与系统管理员联系。','数据库连接错误!',MB_OK);
          Application.Terminate;
        end;
        if T_user.RecordCount=1 then
        begin
          if T_user['PASSWD']=edtPswd.Text then
          begin
            login.Hide;
            login.Free;
            if not Assigned(Main) then
              Main:=TMain.Create(Application);
            Main.Show;
          end
          else begin
            Application.MessageBox('请重新输入密码,注意大小写!','密码不正确',MB_OK);
          end;
        end
        else
          Application.MessageBox('请确认用户名是否正确!','无此用户',MB_OK);
        end;
    end;procedure Tlogin.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Action :=caFree;
    end;end.
      

  6.   

    不要再主窗体onshow的时候创建登陆窗体,至少要在oncreate的时候
    并且showmodal之前一定要application.showmainform:=false;
    除非适用halt非正常退出,否则你的主窗体会显示出来人后再结束程序。
    一定要用application.terminate,close不可以
      

  7.   

    为何不可以将LOGFORM设为MAINFORM?
    GZ
      

  8.   

    我经常在工程文件中改变窗体的启动顺序,也可在主窗体的CREATE事件中写