procedure TFMain.FormActivate(Sender: TObject);
begin
  OnActivate := nil;
  if not UserLogin then
    Application.Terminate;
end;function TFMain.UserLogin:Boolean;//打开登录对话框
var
  FLogin : TLoginForm;
begin
  Result := False;
  FLogin := TLoginForm.Create(Application);
  try
    if FLogin.ShowModal=mrOK then
      Result := True;
  finally
    FLogin.Free;
  end;
end;

解决方案 »

  1.   

    不会吧!不有一个我做的登录窗口中的Buttonclick事件:
    procedure Tlogin_on.Button1Click(Sender: TObject);
    var
     s1,s2:string;
    begin

    //验证密码
     if t_password<>l_password.Text then
     begin
      if messagedlg('错误的密码或用户名,请重新输入',mterror,[mbok,mbcancel],0)=mrok then
       log_num:=log_num-1;
      if log_num<1 then
      begin
       mainform.close;
       login_on.Close;
      end;
     end
     else
     begin
      if t_usertype<>'管理员'then
      begin
       mainform.n2.visible:=false;
       mainform.N3.Visible:=false;
      end;
      login_on.Close;//用此语句就可关闭登录窗体。
     end;
    end
    else
     messagedlg('用户名不能为空,请重新输入',mtwarning,[mbok],0);
    end;
      

  2.   

    unit pass;interfaceuses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
      Buttons, Db, ADODB,Dialogs;type
      TPasswordDlg = class(TForm)
        Label1: TLabel;
        Password: TEdit;
        OKBtn: TButton;
        CancelBtn: TButton;
        Label2: TLabel;
        Edit1: TEdit;
        ADOQuery1: TADOQuery;
        ADOConnection1: TADOConnection;
        Label3: TLabel;
        procedure OKBtnClick(Sender: TObject);
        procedure CancelBtnClick(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      PasswordDlg: TPasswordDlg;
      timestag:integer;implementationuses masmain, assemble,  masorderm,
       onprocuct, opdetail, product, reme,  resor,
      taskp, tough, workhour, delayrep, halfproduct, center, dayreport, squad,
      midplan, item, matchtool;{$R *.DFM}procedure TPasswordDlg.OKBtnClick(Sender: TObject);
    var
    pwstag,mannum:string;
    begin
      if timestag<=2 then
      begin
      adoconnection1.Connected:=true;
      adoquery1.Close;
      adoquery1.SQL.Clear;
      adoquery1.SQL.Add('select man_pw from mas_mpi where man_name=:mannum');
      mannum:=edit1.text;
      adoquery1.Parameters[0].Value:=mannum;  adoquery1.Open;
      if adoquery1.recordcount=0 then
      begin
        showmessage('请输入正确的登录帐号');
        edit1.Text:='';
        password.Text:='';
      end
      else
      begin
          pwstag:=trimright(adoquery1.FieldByName('man_pw').asstring);
          if password.Text=pwstag then
          begin
          main.showmodal;
          application.Terminate;
          end
          else if password.Text<>pwstag then
          ShowMessage('输入密码有误');  end
     end 
     else if timestag>=2 then
     begin
       application.Terminate;
     end;
      timestag:=timestag+1;
    end;procedure TPasswordDlg.CancelBtnClick(Sender: TObject);
    begin
      close;
    end;procedure TPasswordDlg.FormCreate(Sender: TObject);
    begin
       edit1.Text:='';
       password.Text:='';
       timestag:=1;end;end.