我做了一个登陆界面,点击添加用户按钮,添加了用户,但是把刚刚添加的用户输入登陆框中,就出错,说数据库没有这个用户字段,我把程序关了重新运行以后,又可以登陆了,为什么不能在添加完就直接登陆,我的代码如下。
添加按钮的代码: procedure checkinput(theedit:tedit;strdesc:string);
    begin
       theedit.Text:=trim(theedit.Text);
       theedit.Text:=stringreplace(theedit.Text,'''','',[rfreplaceall]);
       theedit.Text:=stringreplace(theedit.Text,' ','',[rfreplaceall]);
       if theedit.Text='' then
         begin
             showmessage(strdesc);
             theedit.SetFocus;
             abort;
         end;
    end;
begin
     checkinput(edit1,'请输入操作员名!');
     checkinput(edit2,'请输入口令!');    with query1 do
    begin
        active:=false;
        sql.Clear;        sql.Add('insert into users(username,passwd)');
        sql.Add('values((:a),(:b))');
        params[0].AsString:=edit1.Text;
        params[1].AsString:=edit2.Text;        execSQL;
    end;    showmessage('添加成功!');
    edit1.Clear;
    edit2.Clear;登陆按钮代码:
 procedure checkinput(theedit:tedit;strdesc:string);
  begin
     theedit.Text:=trim(theedit.Text);
     theedit.Text:=stringreplace(theedit.Text,'''','',[rfreplaceall]);
     theedit.Text:=stringreplace(theedit.Text,' ','',[rfreplaceall]);
     if theedit.Text='' then
     begin
        showmessage(strdesc);
        theedit.SetFocus;
        abort;
     end;
  end;
begin   checkinput(edtusername,'请输入操作员名!');
   checkinput(edtPasswd,'请输入口令!');
   query1.Active:=false;
   query1.ParamByName('UserName').AsString :=edtusername.Text;
   query1.ParamByName('passwd').AsString :=edtpasswd.Text;
   query1.Active:=true;
   if query1.Eof then
   begin
     showmessage('操作员名或者口令不正确!');
     edtusername.SetFocus;
     inc(times);
   end
   else
       modalresult:=mrOK;
   if times>=3 then
   begin
      showmessage('非法用户无权登陆!');
      modalresult:=mrcancel;
   end;