delphi做登陆界面,有个问题,第一次点确定不行,第二次才会成功,跪求高手指点
procedure TForm1.Button1Click(Sender: TObject);
begin
try
with adoquery1 do
begin
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from users where user_id='''+edit1.text+''' and password='''+edit2.text+'''and authority='''+value+'''');
adoquery1.open;
if Edit1.Text ='' then
begin
application.MessageBox('请输入用户名','提示信息',64);
edit1.SetFocus;
exit;
end;
if edit2.Text ='' then
begin
application.MessageBox('请输入密码','提示信息',64);
edit2.SetFocus;
exit;
end;
if radiobutton1.Checked=true then
begin
value:='1'; //管理员
end;
if radiobutton2.Checked=true then
begin
value:='0'; //普通用户
end;
//open;
end;
if adoquery1.RecordCount<>0 then
begin
if trim(adoquery1.fieldbyname('password').asstring) = trim(Edit2.text) then
application.MessageBox('登陆成功','提示信息',64);
form2.show;
end
else
application.MessageBox('输入的用户名或密码错误','警告',64);
except
application.MessageBox('登陆失败','提示信息',64);
end;
end;
答案:代码顺序问题。查询时authority='''+value+'''',这个value从何而来?是来自后面的radiobutton检查。别人写程序都是把查询放在最后,你倒是反向而行之。
上一个:delphi用savedialog1控件的一个问题,怎么做,谢谢
下一个:delphi 数据库问题!