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

解决方案 »

  1.   

    在项目工程单元里
    begin
      application.ini...;
      passform.create()
      passform.showmodal;
      if passok then begin
        mainform.create
        application.run...;
      end;
      passform.free;
    end.
      

  2.   

    为了分数,也顾不得了。
    以下是我的一个例子,需要用passworddlg,在file-->new-->dialog下,可以满足你的要求,若要改变主窗体的borderstyle,只需在mainform.showmodal前设置其属性为bssingle即可。
    program Project1;uses
      Forms,
      Controls,
      Dialogs,
      Unit1 in 'Unit1.pas' {Form1},
      Unit2 in 'Unit2.pas' {PasswordDlg};{$R *.RES}begin
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.ShowMainForm:=false;
      Application.CreateForm(TPasswordDlg, PasswordDlg);
      PasswordDlg.ShowModal;
      while PasswordDlg.ispass=False do{ispass是passworddlg的一个在public下声明的    boolean变量}
      begin
      if (MessageDlg('please input the password',MtInformation,[mbYes,mbNo],0)=mryes) then
      Passworddlg.ShowModal
      else exit;
      end;
      if PasswordDlg.ispass then
      begin
      application.ShowMainForm:=true;
      Application.Run;
      PasswordDlg.Free;
      PasswordDlg:=nil;
      end
      //application.Terminate;
    end.
      

  3.   

    program Project1;uses
      Forms,
      Unit1 in 'Unit1.pas' {Form1},
      Unit2 in 'Unit2.pas' {Form2};{$R *.res}begin
      Form1:=TForm1.Create(Application);
      try
        Form1.ShowModal;//密码窗体
      finally
        Form1.Free;
      end;
      if exit=false then
        begin
          Application.CreateForm(TForm2, Form2);//主窗体
          Application.Run;
        end;
    end.procedure TForm1.FormShow(Sender: TObject);
    begin
      exit:=true;
    end;如果错误输入三次,exit就不变。然后关闭密码窗体就行了。
    Exit是在主窗体中设的全局变量。
      

  4.   

    用户权限模块的一部分。
    =====================
    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\aa.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;