这个如果连续3次密码输入错误,程序会自动关闭 var count: Integer=0; //登录次数计数procedure TForm1.FlatButton1Click(Sender: TObject); begin count := count+1; if ADODataSet1.Locate('帐号',NameEdit.Text,[])= false then begin MessageBox(form1.Handle,'此管理员不存在!','出错',MB_OK+MB_ICONERROR); exit; end; res:=adodataset1.FieldValues['密码']; if res=PwdEdit.Text then begin count:= 0; AdminForm.show; NameEdit.Clear; PwdEdit.Clear; CheckBox1.Checked:= false; form1.Hide; end else begin MessageBox(form1.Handle,'密码输入有误!','出错',MB_OK+MB_ICONERROR); if count=3 then close; end; end;
sqlStr:='select pwd from usermessage where username='+combobox.text; adoQuery.sql.add(sqlStr); adoQuery.open;if adoQuery.recordcount<=0 then 密码错误
有问题:应该是 if adoQuery.FieldValues['pwd']<> 输入密码 then 密码错误;
这只是针对只有一个用户的,如果数据库表中有2个以上的记录如何写? i := StrToInt(cbxUserName.Items[cbxUserName.ItemIndex]); //取出所选的用户名的索引值,然后找对应的密码,但下一句我不会写 pwd := table.FieldByName('Pwd'); //这句怎么写?要求是取出pwd字段中索引为i的值。
var
count: Integer=0; //登录次数计数procedure TForm1.FlatButton1Click(Sender: TObject);
begin
count := count+1; if ADODataSet1.Locate('帐号',NameEdit.Text,[])= false then
begin
MessageBox(form1.Handle,'此管理员不存在!','出错',MB_OK+MB_ICONERROR);
exit;
end;
res:=adodataset1.FieldValues['密码'];
if res=PwdEdit.Text then
begin
count:= 0;
AdminForm.show;
NameEdit.Clear;
PwdEdit.Clear;
CheckBox1.Checked:= false;
form1.Hide;
end
else
begin
MessageBox(form1.Handle,'密码输入有误!','出错',MB_OK+MB_ICONERROR);
if count=3 then close;
end;
end;
adoQuery.sql.add(sqlStr);
adoQuery.open;if adoQuery.recordcount<=0 then 密码错误
if adoQuery.FieldValues['pwd']<> 输入密码 then 密码错误;
i := StrToInt(cbxUserName.Items[cbxUserName.ItemIndex]);
//取出所选的用户名的索引值,然后找对应的密码,但下一句我不会写
pwd := table.FieldByName('Pwd');
//这句怎么写?要求是取出pwd字段中索引为i的值。