关于tedit控件(很弱智的问题,但是小妹妹我就是不会做)

marrylove 2001-07-31 01:29:40
我做一个登陆页面,我想在登陆者输入完用户名之后,在输入密码时,把鼠标刚放在输入密码这个edit,但是还没有输入密码时,执行查询数据库的操作,如果没有这个用户名时,则出提示框,告诉用户此用户名有错,这应该如何写
...全文
102 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ExitWindows 2001-08-01
  • 打赏
  • 举报
回复
up
ExitWindows 2001-07-31
  • 打赏
  • 举报
回复
up
flypuma 2001-07-31
  • 打赏
  • 举报
回复
li_zhifu是对的,有几点可以商榷:
1 是否把代码放在 Username 控件的 OnExit 事件上,这样只要焦点离开了UserName输入区
就执行核查,逻辑上更好一些,我这么认为的,:-)
2 Query1.sql.add('select count(Name) from user where Name='#39+edit1.text+#39);
Query1.active:=True;
if query1.Fields[0].AsInteger = 0 then
showmessage('No this User'+' '+edit1.text);
这样就不用将整条记录返回来了,只需要取回感兴趣的内容就可以了...
prometheusphinx 2001-07-31
  • 打赏
  • 举报
回复
假如marrylove的密码如下判断那就完蛋啦,
'select * from user where Name='#39+edit1.text+#39 + ' and password='#39+edit2.txt+#39
delphi_user 2001-07-31
  • 打赏
  • 举报
回复
同意li_zhifu()
bubble 2001-07-31
  • 打赏
  • 举报
回复
我建议这样写:在输用户名的Edit中写代码procedure TLoginForm.UserEditKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
with Query1 do
begin
Close;
SQL.Clear;
SQL.Add('Select *');
SQL.Add('From 表 别名');
SQL.Add('Where 条件');
ParamByName('cn').AsString:=UserEdit.Text;
Open;
if recordcount<>0 then PasswordEdit.SetFocus
else
begin
if MessageDlg('没有该用户!是否继续?',mtConfirmation,
[MBYes,MBNo],0)=mrYes then
begin
UserEdit.Clear;
UserEdit.SetFocus;
end;
end;
Close
end;
end;
end;
tempest 2001-07-31
  • 打赏
  • 举报
回复
我想li_zhifu的回答正确!
sinocat 2001-07-31
  • 打赏
  • 举报
回复
right
li_zhifu 2001-07-31
  • 打赏
  • 举报
回复
我这只是回答marrylove的问题,至于要登录,marrylove自然还要对密码进行验证.
BCB 2001-07-31
  • 打赏
  • 举报
回复
同意楼上的说法,通用做法是:等密码输入完毕,方才处理,第一步不要告诉用户对不对
prometheusphinx 2001-07-31
  • 打赏
  • 举报
回复
li_zhifu:你的代码写得没错,但这种写法存在一个安全漏洞,
如果以这种方法判断的话,我不需要知道数据库中的任何用户名或密码便可登入。
li_zhifu 2001-07-31
  • 打赏
  • 举报
回复
在密码的Edit2的OnEnter事件中写

Query1.Active:=False;
Query1.Sql.Clear;
Query1.sql.add('select * from user where Name='#39+edit1.text+#39);
Query1.active:=True;
if query1.recordcount<=0 then
showmessage('No this User'+' '+edit1.text);

5,930

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧