如何在delphi里实现登录系统

来源:百度知道 编辑:UC知道 时间:2024/05/13 18:21:44
我的sql和delphi连接成功后,我想在登陆界面点击确定后实现对我的表(person)的访问,密码正确后然后进入下一界面,我以下的程序那里有问题?
procedure TF_login.Button1Click(Sender: TObject);
begin
with ADOQuery1 do
begin
if ((edit1.Text='')and (Edit2.Text=''))then
begin
Application.MessageBox('您输入的用户名或密码不能为空!请重新输入!','警告',mb_ok);
Edit1.Text:='';
Edit2.Text:='';
Edit1.SetFocus;
exit;
end;
first;
while ADOQuery1.Eof = False do
begin
if ((edit1.Text=FieldByName('person_name').asString)and(Edit2.Text=FieldByName('person_password').asString)) then
begin
Application.MessageBox('您输入的用户名或密码正确!','提示',mb_ok);
F_login.Visible:=False;
F_administrator.ShowModal;
F_login.close;
end;
next;
end;
Application.MessageBox('您输入的用户名或密码错误!请重新输入!'

你写的登录系统的逻辑很乱~
建议你看一下书或别人是怎么写的

first; //在这之前ADOQuery1有没有Open ?

还有
while ADOQuery1.Eof = False do
begin
if ((edit1.Text=FieldByName('person_name').asString)and(Edit2.Text=FieldByName('person_password').asString)) then
begin
Application.MessageBox('您输入的用户名或密码正确!','提示',mb_ok);
//在判断到用户名跟密码正确后,最好该块代码不要有再往下执行。
F_login.Visible:=False;
F_administrator.ShowModal;
F_login.close;
end;
next;
end;

if ((edit1.Text=FieldByName('person_name').asString)and(Edit2.Text=FieldByName('person_password').asString)) then
begin
Application.MessageBox('您输入的用户名或密码正确!','提示',mb_ok);
F_login.Visible:=False;
F_administrator.ShowModal;
F_login.close;
end;
next;
end;
Application.MessageBox('您输入的用户名或密码错误!请重新输入!','警告',mb_ok)