求一個有三次限制登錄的登錄窗口代碼?该如何解决
求一個有三次限制登錄的登錄窗口代碼?
procedure Tdenglufrm.Button1Click(Sender: TObject);
var
username ,password :string;
begin
if edit1.Text=''then
messagebox(denglufrm.handle,'请输入用户名','警告',mb_ok+mb_iconwarning)
else
if edit2.Text=''then
messagebox(denglufrm.handle,'请输入密码','警告',mb_ok+mb_iconwarning)
else
begin
username:=edit1.Text;
password:=edit2.Text;
with ADOQuerydl do
begin
close;
sql.clear;
sql.add('select * from xtglry where yh=');
sql.add(''''+username+''''+'and mm='+''''+password+'''');
open;
first;
if recordcount=1 then
begin
denglufrm.Hide;
MainFrm.Show;
end
else
messagebox(denglufrm.handle ,'请输入正确的密码','警告',mb_ok+mb_iconwarning);
edit1.Text:='';
edit2.Text:=''
end;
end;
end;
这个是我的代码,我想添加循环来控制登录三次就退出,应该怎样设置啊?
------解决方案--------------------
i_Times: integer = 3
procedure Tdenglufrm.Button1Click(Sender: TObject);
var
username ,password :string;
begin
if edit1.Text= ' 'then
messagebox(denglufrm.handle, '请输入用户名 ', '警告 ',mb_ok+mb_iconwarning)
else
if edit2.Text= ' 'then
messagebox(denglufrm.handle, '请输入密码 ', '警告 ',mb_ok+mb_iconwarning)
else
begin
if i_Times = 0 then
Application.terminate;
username:=edit1.Text;
password:=edit2.Text;
with ADOQuerydl do
begin
close;
sql.clear;
sql.add( 'select * from xtglry where yh= ');
sql.add( ' ' ' '+username+ ' ' ' '+ 'and mm= '+ ' ' ' '+password+ ' ' ' ');
open;
first;
if recordcount=1 then
begin
denglufrm.Hide;
MainFrm.Show;
end
else
begin
messagebox(denglufrm.handle , '请输入正确的密码 ', '警告 ',mb_ok+mb_iconwarning);
edit1.Text:= ' ';
edit2.Text:= ' ';
Dec(i_Times,1);
end;
end;
end;
end;
------解决方案--------------------
增加一个全局变量,每登录一次就开始判断
var
LoginCount:byte;
procedure Tdenglufrm.Button1Click(Sender: TObject);
var
username ,password :string;
begin
if loginCount>3 then
exit;//大于三次退出
if edit1.Text= ' 'then
messagebox(denglufrm.handle, '请输入用户名 ', '警告 ',mb_ok+mb_iconwarning)
else
if edit2.Text= ' 'then
messagebox(denglufrm.handle, '请输入密码 ', '警告 ',mb_ok+mb_iconwarning)
else
begin
username:=edit1.Text;
password:=edit2.Text;
with ADOQuerydl do
procedure Tdenglufrm.Button1Click(Sender: TObject);
var
username ,password :string;
begin
if edit1.Text=''then
messagebox(denglufrm.handle,'请输入用户名','警告',mb_ok+mb_iconwarning)
else
if edit2.Text=''then
messagebox(denglufrm.handle,'请输入密码','警告',mb_ok+mb_iconwarning)
else
begin
username:=edit1.Text;
password:=edit2.Text;
with ADOQuerydl do
begin
close;
sql.clear;
sql.add('select * from xtglry where yh=');
sql.add(''''+username+''''+'and mm='+''''+password+'''');
open;
first;
if recordcount=1 then
begin
denglufrm.Hide;
MainFrm.Show;
end
else
messagebox(denglufrm.handle ,'请输入正确的密码','警告',mb_ok+mb_iconwarning);
edit1.Text:='';
edit2.Text:=''
end;
end;
end;
这个是我的代码,我想添加循环来控制登录三次就退出,应该怎样设置啊?
------解决方案--------------------
i_Times: integer = 3
procedure Tdenglufrm.Button1Click(Sender: TObject);
var
username ,password :string;
begin
if edit1.Text= ' 'then
messagebox(denglufrm.handle, '请输入用户名 ', '警告 ',mb_ok+mb_iconwarning)
else
if edit2.Text= ' 'then
messagebox(denglufrm.handle, '请输入密码 ', '警告 ',mb_ok+mb_iconwarning)
else
begin
if i_Times = 0 then
Application.terminate;
username:=edit1.Text;
password:=edit2.Text;
with ADOQuerydl do
begin
close;
sql.clear;
sql.add( 'select * from xtglry where yh= ');
sql.add( ' ' ' '+username+ ' ' ' '+ 'and mm= '+ ' ' ' '+password+ ' ' ' ');
open;
first;
if recordcount=1 then
begin
denglufrm.Hide;
MainFrm.Show;
end
else
begin
messagebox(denglufrm.handle , '请输入正确的密码 ', '警告 ',mb_ok+mb_iconwarning);
edit1.Text:= ' ';
edit2.Text:= ' ';
Dec(i_Times,1);
end;
end;
end;
end;
------解决方案--------------------
增加一个全局变量,每登录一次就开始判断
var
LoginCount:byte;
procedure Tdenglufrm.Button1Click(Sender: TObject);
var
username ,password :string;
begin
if loginCount>3 then
exit;//大于三次退出
if edit1.Text= ' 'then
messagebox(denglufrm.handle, '请输入用户名 ', '警告 ',mb_ok+mb_iconwarning)
else
if edit2.Text= ' 'then
messagebox(denglufrm.handle, '请输入密码 ', '警告 ',mb_ok+mb_iconwarning)
else
begin
username:=edit1.Text;
password:=edit2.Text;
with ADOQuerydl do