我做了一个登录子窗口login_form和主窗口main_form,login_form.formstyle设置为fsStayOnTop,我的目的是要程序运行时,login_form处于main_form上层(已实现),并且login_form处于激活状态,设置login_form为SetFocus,但无法实现。请问该如何设置?

解决方案 »

  1.   

    一般上,登陆窗口是要以模态窗口显示的(不用设置fsStayOnTop)
    这样主窗口就不能操作,必须关掉登陆窗口才能继续操作,即if login_form.showmodal=mrCancel then //验证不通过
    application.Terminate;//退出程序
      

  2.   

    login_form用showmodal显示模态,不用ontop,在主窗体的活动事件中创建登录窗体
      

  3.   

    我给段最近写的一个小工程文件你看看program WooFong;uses
      Forms,
      Windows,
      typinfo,
      SysUtils,
      MainForm in 'Pas\MainForm.pas' {frmMain},
      test in 'Pas\test.pas' {FrmEdits},
      Common in 'Pas\Common.pas',
      test2 in 'Pas\test2.pas' {FrmTab},
      GetCPUSerialNO in 'Pas\GetCPUSerialNo.pas',
      RegInfo in 'Pas\RegInfo.pas' {frmRegInfo},
      UserSeting in 'Pas\UserSeting.pas' {frmUserSeting},
      PrdtInfo in 'Pas\PrdtInfo.pas' {frmPrdtInfo},
      DM in 'Pas\DM.pas' {frmDM: TDataModule},
      Login in 'Pas\Login.pas' {frmLogin},
      Logo in 'Pas\Logo.pas' {frmLogo},
      CompanyInfo in 'Pas\CompanyInfo.pas' {frmCompanyInfo},
      CustInfo in 'Pas\CustInfo.pas' {frmCustInfo},
      About in 'Pas\About.pas' {frmAbout},
      CustOrder in 'Pas\CustOrder.pas' {frmCustOrder};{$R *.res}type TDesignUser=(LJJ);var
      hMutex:HWND;
      Ret:Integer;
      hWinHwd:HWND;
      UserName:array[0..20] of char;
      fLength:dword;begin
      Application.Initialize;
      Application.Title:='沃丰纸业信息管理系统';
      hWinHwd:=FindWindow(nil,Pchar('WooFong'));
      SetForeGroundWindow(hWinHwd);
      ShowWindow(hWinHwd,SW_SHOW);
      hMutex:=CREATEMUTEX( nil,TRUE, Pchar('WooFong'));
      Ret:=GetLastError();
      if Ret<>ERROR_ALREADY_EXISTS then
      Begin
        frmLogo:=TfrmLogo.Create(Application);
        frmLogo.Show;
        frmLogo.Update;
        Application.CreateForm(TfrmDM, frmDM);
      Application.CreateForm(TfrmMain, frmMain);
      fLength:=20;
        GetUserName(UserName,fLength);
        if GetEnumValue(TypeInfo(TDesignUser),UpperCase(UserName))<>-1 then
        begin
          frmMain.PUserNo  :='001';
          frmMain.PUserName:='Admin';
          frmMain.PIsAdmin:=True;
        end
        else
          Application.CreateForm(TfrmLogin, frmLogin);
        frmLogo.Hide;
        frmLogo.Close;
        Application.Run;
      End;
      ReleaseMutex(hMutex);
    end.下面是登录窗口的按钮事件procedure TfrmLogin.btnLoginClick(Sender: TObject);
    var
      cBaseRight,
      cRight,
      cUserPass,
      cUserId,
      cUserName:String;  iMenuItemCnt:Integer;
    begin
      cUserName:=Trim(cobUserName.Text);
      if cUserName='' then
      begin
        ShowMessage('用户名不能为空!');
        cobUserName.SetFocus;
        Abort;
      end;  with frmDM.tbUser do
      begin
        if not Locate('UserName',cUserName,[]) then
        begin
          ShowMessage('该用户不存在!');
          cobUserName.SetFocus;
          Abort;
        end
        else
        begin 
          cUserId   :=FieldbyName('UserID').AsString;
          cUserName :=FieldbyName('UserName').AsString;
          cUserPass :=FieldbyName('Password').AsString;      if FieldbyName('IsAdmin').AsInteger=1 then
            frmMain.IsAdmin:=True
          else
            frmMain.IsAdmin:=False;
        end;    if Trim(edtPassword.text)<>cUserPass then begin
          ShowMessage('密码不正确!');
          edtPassword.Clear;
          edtPassword.SetFocus;
          Exit;
        end;
      end;  frmMain.PUserNo  :=cUserId;
      frmMain.PUserName:=cUserName;  frmMain.Visible:=True;
      Application.ShowMainForm:=True;
      frmLogin.Hide;
      //FreeAndNil(frmLogin);
    end;
      

  4.   


    procedure Tmain_form.FormShow(Sender: TObject);
    begin
      main_form.Enabled:=false;
      login_form.ShowModal;
    end;报读取内存出错
      

  5.   

    一般情况下,应该先创建登录窗口进行验证,验证通过后再创建主窗口。否则直接退出。
    首先这是逻辑问题。即先后逻辑问题。如果这个没搞好,很容易出问题的。比如Alt+F4
      

  6.   

    你要先创建登录窗口,才能Showmodal。
    窗口都没有create,如何调用呢?
      

  7.   


    加了create
    报错“cannot create a visible window modal”
      

  8.   

    加了create
    报错“cannot create a visible window modal”
      

  9.   

    让窗体的Visible := false;试一试。