我曾经在onlog中设置了username和password,
可以保证一个用户的默认登陆,
现在我想设计一个对话框,让用户可以选择相应框中的用户名,
再输入密码,(这些用户和密码是真实存在与数据库当中的)。
此时不知道如何设置这两个参数传递到onlog函数中?
或则有什么更好的办法可以对用户的登入参数进行传递!
请高手指教!
不胜感谢!

解决方案 »

  1.   


    DataMoudle中定义LogIn函数,根据查询登录对话框传来参数查询数据库,然后返回结果。
      

  2.   

    UserName 从 ComboBox 中取,Password 是用户输入的,将 UserName 和 Password 做为参数传递到一个函数中,用这个函数来验证用户名和密码的正确性。
      

  3.   

    我也是用combobox来取用户,
    password是用户输入的,
    但是如何把username和password作为参数传递到某个函数,怎样的函数
    中进行判断呢?
      

  4.   

    我以前在bcb中是这么做的:
    在一个DataMoudle中放一个database,(例子中是Db1),在它的 Login 和 AfterConnect 事件中处理,delphi没用过,应该差不多void __fastcall TDM1::Db1Login(TDatabase *Database, TStrings *LoginParams)
    {
      TFDBLogin* form = new TFDBLogin(this);
      if (form->ShowModal() == mrOk)
      {
        UserName = form->UName->Text;
        Password = form->PWD->Text;    LoginParams->Values["USER NAME"] = "sa";
        LoginParams->Values["PASSWORD"] = "";
        delete form;
      }
      else
      {
        delete form;
        Application->Terminate();
      }
    }
    //---------------------------------------------------------------------------
    void __fastcall TDM1::Db1AfterConnect(TObject *Sender)
    {
      AnsiString Sql = "";
      if ( Password != "" )
        Sql = "select bm from bdwry where bm='"+UserName+"' and yhmm='"+Password+"'";
      else
        Sql = "select bm from bdwry where bm='"+UserName+"' and yhmm is null";  QueBdwry->SQL->Clear();
      QueBdwry->SQL->Add(Sql);
      QueBdwry->Open();
      if (!QueBdwry->RecordCount)
      {
        if ( IsSuperUser(UserName) )
        {
          MainWin->IsSuperUser = true;
        }
        else
        {
          ShowMessage("无效的用户名或密码!");
          Application->Terminate();
        }
      }
    }
      

  5.   

    const
       connstr='Provider=SQLOLEDB.1;Password=%s;Persist Security Info=True;User ID=%s;Initial Catalog=kaper_cpc;Data source=%s';
    begin
         try
          DataModule.linkto.ConnectionString:=
               format(connstr,[passedit.text,useredit.text,datasure.text]);
          DataModule.linkto.Open;
         except
            on EOleException do
               begin
               mainform.syshint('联接错误!','',1);
               datamodule.linkto.Close;
               end;
          end;
         close;
    end;                //linkto为datamodule上一ADOconnection,其loginprompt设为FALSE!
      

  6.   

    to  zhanghk:
    你的方法我认为有一个漏洞,
    那就是如果是对象oracle这样分级管理的数据库而言,
    你的用户只要是成功登入的,那么都具有sa的权限,
    当然你的方法上指对sql server数据库。
    所以,为了不能让它具有登入用户不改具有的权限,
    应该是在login时进行合法用户是否的判断,
    而不是在afterconnect中判断,
    这样是错误的!
      

  7.   

    其实你可以完全自己设计一个login窗体,用combobox放用户名,edit放密码,用两个button控件一个用来进行登录、一个用来退出系统。在登录按钮在加入代码:
    with table1 do
            begin
                  setkey;
                  fieldbyname('name').asstring:=combobox1.text;
                  if gotokey then
                     if edit2.text=fieldbyname('pass').asstring then
                        showmessage('登录成功!')
                      else
                        showmessage('密码错误,请确认!');  
              end;
    end;