为什么一下子弹出两个界面,我做的是登录界面,还没输密码呢,发现后面的窗体全出来了,太悲催了,是不是我用了两个ADOconcection的原因呢

解决方案 »

  1.   

    project->options->forms把不需要启动的移动右边
      

  2.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
        ADOConnection1.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(ParamStr(0))+'\cw.mdb;User ID=admin;Password=;'+'Persist Security Info=true;Jet OLEDB:Database Password=111';
        ADOTable1.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;DataSource='+ExtractFilePath(ParamStr(0))+'\cw.mdb;UserID=admin;Password=;'+'Persist Security Info=true;Jet OLEDB:Database Password=111';
        ADOquery1.Connection:= ADOConnection1;
        with adoquery1 do
        begin
            close;
            sql.Clear;
            sql.Text:='select 用户名 from 用户表';
            open;
            combobox1.Clear;
            while not eof do
            begin
                combobox1.Items.add(fields[0].asstring);
                if ComboBox1.Items.Count >0 then  ComboBox1.ItemIndex := 0;
                next;
            end;
        end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
        if combobox1.text='' then
        begin
            showmessage('用户名不能为空');
            exit;
        end;
        if edit2.Text='' then
        begin
            showmessage('密码不能为空');
            exit;
        end;
        with adoquery1 do
        begin
            close;
            sql.Clear;
            sql.Add('select * from 用户表 where 用户名='''+combobox1.text+''' and 密码='''+edit2.Text+'''');
            open;
            if adoquery1.RecordCount<>0 then
            begin
                form2.show;
                form1.Visible := false;
            end
            else
            begin
            showmessage('用户名或密码不正确,请重新输入');
            exit;
            end;
        end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
        form1.Close;
    end;
      

  3.   

    不是ADOCONNECTION的问题,
    看看是不是你的 
    if trim(edit2.Text)='' then
      begin
      showmessage('密码不能为空');
      exit;
      end;//这样试试
      

  4.   

    控制窗体自动create,动态创建.
      

  5.   

    project->options->formsmainform 设为登录的窗口
    if adoquery1.RecordCount<>0 then
    begin
     form1.hide;
    form2.ShowModal;
    end;
    form2.Show;会执行后面的语句;
    form2.ShowModal 关闭后才会执行后面的语句
     
      

  6.   

    可能需要修改一下主文件,加入一句
    Application.ShowMainForm:=False
    还有,把其它的FORM设成不自动创建
    当然还要做一番调整才可以