procedure TForm1.Button1Click(Sender: TObject);
var pw,s:integer;
begin
// n:=0; //n是一个全局变量,这里不能给它赋值,否则n就失去全局变量的意义,
//将导致每次按【确定】按钮,都使n:=0,使n无法累加
pw:=123456;
if edit1.text='' then
s:=0
else s:=strToInt(edit1.Text);
if n<3 then
begin
if s<>pw then
Begin
n:=n+1;
if n=3 then
Begin
edit1.Visible :=false;
button1.Visible :=false;
button2.Visible :=false;
button3.SetFocus ;
label1.Visible :=false;
label2.Top:=285;
label2.Font.Size :=16;
label2.Height :=30;
label2.Width:=400;
label2.Visible :=true;
Label2.Caption :='密码错误3次,请【退出系统】!';
end
else
begin
button2.Visible :=true;
label2.Font.Color:=clRed;
label2.Visible :=true;
Label2.Caption :='第 '+intToStr(n)+' 次密码错误,请重输密码!';
end;
end
else
begin
label1.Visible :=false;
edit1.Visible :=false;
button1.Visible :=false;
button2.Visible :=false;
label2.Height :=30;
label2.Width:=400;
label2.Top:=285;
label2.Font.Size :=16;
label2.Font.Color :=clgreen;
label2.Visible :=true;
Label2.Caption :='密码正确,欢迎使用本系统!';
end;
end;
end;
转载于:https://blog.51cto.com/tzlin/592430