下面这种方法好像不行,在我这里总是提示下面这具有错误:if EntryFrm.ShowModal=mrOK then⑴让登录窗体在主窗体运行前打开,
⑵根据登录窗体返回值判断主窗体是否应该运行。
详细代码如下://project.dpr文件program project;
... ...
... ...begin
 Application.Initialize;
    EntryFrm:=TEntryFrm.Create(application); //登录窗口
   if EntryFrm.ShowModal=mrOK then          //登录窗体关闭时返回了mrOK值,说明登录成功
   begin
     Application.CreateForm(TMainFrm, MainFrm);
     //其它auto-create forms
   end;
   EntryFrm.Free;
   application.Terminate
 Application.Title := '某某管理系统';
 Application.Run;
end. //entry.pas 登录窗体文件
var
 count:short;              //登录次数{$R *.dfm}procedure TEntryFrm.BitBtn2Click(Sender: TObject);//取消登录
begin
 application.Terminate;
end;procedure TEntryFrm.BitBtn1Click(Sender: TObject);//确定登录
begin
 Inc(count);
 ID:=edit1.Text;          //帐号
 Pas:=edit2.Text;         //密码;ID,Pas是全局变量
//※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※//
 IDInfo.Open;
 if IDInfo.Locate('ID',ID,[]) then
 begin
   if StrEncry(IDInfo.FieldByName('Pas').AsString)=Pas then //密码解密,登录成功
   begin
     Pop:=IDInfo.fieldbyname('Pop').AsString;               //取得权限
     writelog(ID,'登录');                                   //写入日志
     self.ModalResult:=mrOK;                                //关闭窗口并返回mrOK值
   end;
 end;
 if count>=3 then self.ModalResult:=mrabort;                //只允许登录3次
 IDInfo.Close;
//※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※//
 edit1.Text:='';
 edit2.Text:='';
 edit1.SetFocus;
end;

解决方案 »

  1.   

    直接给出两个edit分别表示“用户名”和“密码”procedure Tfmlogin.BitBtn1Click(Sender: TObject);
    var
    pw,edtpasswd:String;
    begin
    if  Trim(edtuse.Text)='' then
    begin
    showmessage('用戶名不能為空﹗');
    exit;
    end;if  Trim(edtpw.Text)='' then
    begin
    showmessage('密碼不能為空﹗');
    exit;
    end;useid:=Trim(edtuse.Text);dm.adoc.connected:=false;
    dm.aqquery.Close;
    dm.aqquery.SQL.Clear;
    dm.aqquery.SQL.Add(' select count(*) as num ,useid,passwd,useqx from useinfor where useid='''+Trim(edtuse.Text)+''' group by useid,passwd,useqx ');
    dm.aqquery.Open;if (dm.aqquery.FieldValues['num']<=0) then
    begin
    showMessage('系統中沒用該用戶﹗');
    exit;
    end;
     pw:= Trim(dm.aqquery.FieldValues['passwd']);
     edtpasswd:=Trim(edtpw.Text);
     useqx:= Trim(dm.aqquery.FieldValues['useqx']);if not (edtpasswd=pw) then
    begin
    showmessage('密碼不正確﹗');
    exit;
    end;fmlogin.Visible:=false;
    Application.CreateForm(Tfmmain, fmmain) ;
    fmmain.ShowModal;
    fmmain.Release;
    BitBtn1.Enabled:=false;end;
      

  2.   

    if Show_FormLogin then
        begin
          Application.CreateForm(Tfrmmain, frmmain);
          Application.Run;
       end
     else  begin
       application.run;
        application.Terminate;
      end;
    ---------------------------------------------
    以上写在工程文件内
    ____________________________________
    procedure Tfrmlogin.qdClick(Sender: TObject);/////////////确定登陆按钮单击事件
    begin
      with dm.cxq2 do
      begin
        close;
        sql.Clear;
        sql.Add('select * from PSWord where PSW_NAME='''+nl.Text+'''');
        open;
        if recordcount=1 then
        begin
          czy:=nl.Text;
          qx:=fieldbyname('psw_qx').AsString;
          if trim(fieldbyname('PSW_PSword').asstring)=trim(pass.Text) then
          begin
             ModalResult := IdOk;
          end;
        end;
      end;
    end;
      

  3.   

    Show_FormLogin 是什么东西?能给个源程序吗?
    if Show_FormLogin then
        begin
          Application.CreateForm(Tfrmmain, frmmain);
          Application.Run;
       end
     else  begin
       application.run;
        application.Terminate;
      end;