我做了一个登陆窗体和一个主界面窗体,希望先出现登陆窗体,输入密码通过验证后登陆窗体消失,主窗体显示,主窗体的BORDERSTYLE为BSSINGLE,两个窗体VISIBLE为FALSE;在主窗体ONACTIVE的时候登陆窗体ShowModal,验证密码后登陆窗体CLOSE,主窗体显示出来,但同样的我只把主窗体的BORDERSTYLE改为BSSIZEABLE后运行就会两个窗体同时出现,我想在验证时只出现登陆窗体而且主窗体BORDERSTYLE又为BSSIZEABLE怎么办?
谁给个详细的解决方法,或例程。

解决方案 »

  1.   

    在主窗体ONCreate事件里写,而不是ONACTIVE
      

  2.   

    用户权限模块的一部分。
    =====================
    unit UserCtl;interfaceUses  Classes, Forms ,Windows ,SysUtils ,ADODB, IniFiles;Type   TAppUser = Class(Tobject)
       Private
         UserID :String;
       Public
         UserName :String;
         UserType :Integer;
         Connection :TAdoConnection;
         constructor Create();
         destructor Destroy();override;
         Function Login():Boolean;
         Procedure SetPower();
         Procedure RelasePower();
       end;Var AppUser:TAppUser;implementation
    uses Logon ,Main;Const IniName ='AppInfo.ini';
          U_SQL ='Select * From Operator Where ID=:UID and Pwd=:UPwd';
          ErrTitle = '´íÎóÌáʾ';{ UserInfo }constructor TAppUser.Create;
    Var Ini:TIniFile;
    begin
      inherited;
      Ini :=TIniFile.Create(ExtractFilePath(Application.ExeName)+IniName);
      try
        UserID:=Ini.ReadString('Init','DefaultUser','');
      finally
        Ini.Free;
      end;
    end;destructor TAppUser.Destroy;
    begin
      inherited;end;
    //============================Óû§µÇ¼ģ¿é==============================
    function TAppUser.Login(): Boolean;
    Var Q_User:TAdoQuery;
        Password :String;
        LogTimes :Integer;
        Loged :Boolean;
        Ini:TIniFile;
    begin
      LogTimes :=0;
      Loged :=False;
      LoginForm :=TLoginForm.Create(Application);
      LoginForm.Again :=False;
      Q_User :=TAdoQuery.Create(nil);
      Try
          Q_User.Connection :=Connection;
          Q_User.SQL.Text :=U_SQL;
          LoginForm.Caption :='ÇëµÇ¼ϵͳ';
          Repeat
            if LogTimes=3 then Break;
            LoginForm.IdEdit.Text := UserID;
            LoginForm.PwdEdit.Clear;
            if LoginForm.ShowModal =2 then break;
            LoginForm.Again :=True;
            Inc(LogTimes);
            UserID:=LoginForm.IdEdit.Text;       //改 
            Password :=LoginForm.PwdEdit.Text;   //改
            Q_User.Close;
            Q_User.Parameters.ParamByName('UID').Value :=UserID;
            Q_User.Parameters.ParamByName('UPwd').Value :=Password;
            Q_User.Open;
            if Q_User.RecordCount<>0 then
            Begin
              UserName :=Q_User.FieldByName('Name').AsString;
              UserType :=Q_User.FieldByName('Type').AsInteger;
              Loged :=True;
              Ini :=TIniFile.Create(ExtractFilePath(Application.ExeName)+IniName);
              try
                Ini.WriteString('Init','DefaultUser',UserID);
              finally
                Ini.Free;
              end;
            end
            Else Application.MessageBox('&Oacute;&Atilde;&raquo;§&Atilde;&ucirc;&raquo;ò&Atilde;&Uuml;&Acirc;&euml;&acute;í&Icirc;ó',ErrTitle,MB_OK OR MB_ICONERROR);
          Until Loged;
          Result :=Loged;
      finally
          LoginForm.Free;
          Q_User.Free;
      end;
    end;procedure TAppUser.SetPower();
    begin
    With MainForm do
      Begin  end;
    end;procedure TAppUser.RelasePower();
    begin
    //
    end;
    initialization
      AppUser:=TAppUser.Create();finalization
      AppUser.Free;end.//============用法=================
    procedure TDM.DMCreate(Sender: TObject);
    begin
      MainConnect.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\DB\AmWayDB.mdb;Persist Security Info=False';
      Try
         MainConnect.Connected :=True;
      Except
         Messagebox(0,'&Aacute;&not;&frac12;&Oacute;&Iuml;&micro;&Iacute;&sup3;&Ecirc;&yacute;&frac34;&Yacute;&iquest;&acirc;&sup3;&ouml;&acute;í&pound;&not;&Ccedil;&euml;&frac14;ì&sup2;é&pound;&iexcl;','&acute;í&Icirc;ó',MB_OK OR MB_ICONERROR);
         Application.Terminate;
      end;
      AppUser.Connection :=MainConnect;
      if not AppUser.Login then Application.Terminate;
      
    end;
      

  3.   

    做一个函数来创建登陆页面.
    如:
    Function loginover : boolean;
    begin
      application.CreateForm(TloginForm,loginform);
      loginform.showmodal;
      ......
      result:=登陆成功.
      loginform.free;
    end;在.dpr文件中写入以下代码.
    begin
      Application.Initialize;
      Application.CreateForm(TMainForm, MainForm);  IF not Loginover then MainForm.Free;//MainForm是主程序.
      Application.Run;end.
      

  4.   

    你可以在工程的单元里写,先把登陆窗体,不要自动创建就行了
    这是工程单元文件:
    program ycerp;uses
      Forms,
      Unit2 in 'Unit2.pas' {LoginForm},
      MainForm in 'MainForm.pas' {Main_form},
      AddGroup in 'AddGroup.pas' {Add_group};{$R *.res}begin
      Application.Initialize;
      LoginForm := TLoginForm.Create(Application);
      LoginForm.ShowModal;
      LoginForm.Free;
      Application.CreateForm(TMain_form, Main_form);
      Application.Run;
    end.这样的话,只有在你在LoginForm里判断它输入不满足条件以后,你就让程序结束(Application.Terminate),满足条件好就关闭窗口就行了(LoginForm.close),那样
    主窗口就显示出来了,Loginform一定从Auto Create里去掉。
    还有什么不明白,就用QQ联系我就行了,QQ:106873731