重新登录窗体怎么做啊?

解决方案 »

  1.   

    file-->new-->dialogs-->passworddialog就是一个密码登陆窗口,很好用。
      

  2.   

    unit UserCtl;
    //write by minidog
    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('用户名或密码错误',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.
      

  3.   

    我做过一个,你借鉴一下。
    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
      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.
    其中ispass:boolean定义在密码登陆窗口的public里,是确定登陆密码是否正确。
    在密码登陆窗口的确定按钮的click事件中确定密码,如下:
    procedure TPasswordDlg.OKBtnClick(Sender: TObject);
    begin
      if (passworddlg.Password.Text='1') then   //密码为1
      ispass:=true
      else ispass:=false;
    end;
      

  4.   

    file-->new-->dialogs-->passworddialog就是一个密码登陆窗口,很好用。