一个初手,做了一个需要密码验证的窗口,可是在登录窗口就算密码输入错误仍旧能进入主窗体。在网上对照其他高人做的登录窗口,没看出问题所在,请高人给予讲解。
下面是登录和工程文件。program Project1;uses
  Forms,
  UMain in 'UMain.pas' {main},
  UDM in 'UDM.pas' {DM: TDataModule},
  USC in 'USC.pas' {SC},
  SysUtils,
  Dialogs,
  Controls,
  ULOGIN in 'ULOGIN.pas' {LOGIN};{$R *.res}
begin
  application.Initialize;
  Application.CreateForm(Tmain, main);
  Application.CreateForm(TDM, DM);
  Application.CreateForm(TLOGIN,LOGIN);
  LOGIN.ShowModal;
  LOGIN.Free;
  Application.Run;end.登录窗体的登录按钮:
procedure TLOGIN.BitBtn1Click(Sender: TObject);
begin
  Inc(iTimes);
  if Trim(password.Text) = dm.Qoper.FieldByName('pas').AsString then
  begin
    login.Close;
  end
  else
  begin
   Messagebox(0,'密码错误,请重新登录!'+#13#10+'并请确定你是否有进入本系统的权限。','',MB_OK+MB_ICONSTOP);
//   application.Terminate;  //加入这行的意思是实在没办法了,只能强行终止程序。不加这个语句主窗体依然可以进入。
  end;  if iTimes = 4 then
  begin
    application.MessageBox('您进行系统身份确认程序错误已经超过3次,本系统将停止执行。','警告',0);
    application.Terminate;
  end;
end;

解决方案 »

  1.   

    你可以这样写,在调用登陆窗口的模块,比如主窗体中设置一个变量XCLOSE,在登陆窗口中验证身份时根据情况改变这个变量的值,比如通过验证即设置为1,否则设置为0.然后在登陆窗口关闭后让主窗口判断这个变量XCLOSE值,是0则关闭,1则退出
      

  2.   

    begin
     ado.sql.add("sql语句");
    ado.open;
    if ado.eof then
    begin
    showmessage("密码错误");
    end
    else
    begin
    show.主窗体;
    登陆窗体.hide;
    end
      

  3.   

    begin
     ado.sql.add("sql语句");
    ado.open;
    if ado.isempty then
    begin
    showmessage("密码错误");
    exit;
    end
    else
    begin
    主窗体.xclose=1;
    登陆窗体.close;
    end;
    主窗体中相应代码:
    var
      xclose:integer;
    ...
    主窗体.formshow(sender:tobject);
    begin
    xclose:=0;  
    登陆窗体:=Tlogin.create(self);   //Tlogin即为登陆窗体类型
    登陆窗体.showmodule;
    登陆窗体.free;if xclose=0 then
       application.Terminate;
    ...
      

  4.   

    我加了一个DM模块,里面放了一个Qoper(ADOQuery)组件,直接加了SQL语句(select * from logininfo)。Active=true。一启动窗体时就读出loginnfo表的数据。
      

  5.   

    不用这样
    你可以在
    begin
     ado.sql.add("sql语句");
    ado.open;
    if ado.isempty then
    begin里面的 "SQL语句"
    里写成: select * from logininfo where username='''+edituser.text+''' and pwd='''+pwd.text+''' 即可.这样可以省很多启动时间.