📄 unitlogin.pas
字号:
unit UnitLogin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, ExtCtrls;
type
TFormLogin = class(TForm)
LabelName: TLabel;
Image: TImage;
LabelPass: TLabel;
MaskEdit_Pwd: TMaskEdit;
BtnOK: TButton;
BtnCancel: TButton;
Combo_Name: TComboBox;
LabelInfo: TLabel;
LabelWarning: TLabel;
procedure BtnOKClick(Sender: TObject);
procedure BtnCancelClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MyTitle : string;
// 初始密码
MyPwd : string;
//函数返回值
//0 取消登录
//1 Guest登录成功
//2 管理员登录成功
//3 程序员级别的权限 固定密码: ADMIN@JZTX
//4 密码输入错误超过三次
MyValue: short;
end;
const
MAX_INPUT_TIMES = 3;
var
FormLogin: TFormLogin;
//登录次数
Count : short;
implementation
{$R *.dfm}
procedure TFormLogin.BtnOKClick(Sender: TObject);
begin
Inc(Count, 1);
if Count >= MAX_INPUT_TIMES then
begin
MyValue := 4;
Close;
end;
if (Combo_Name.Text = 'Guest') then
begin
MyValue := 1;
Close;
end;
if ( Combo_Name.Text = '管理员' ) and
( MaskEdit_Pwd.Text = MyPwd ) then
begin
MyValue := 2;
Close;
end
else
if ( Combo_Name.Text = '管理员' ) and
( MaskEdit_Pwd.Text = 'ADMIN@JZTX' ) then
begin
MyValue := 3;
Close;
end
else begin
MaskEdit_Pwd.Text := '';
LabelWarning.Caption := '密码输入错误:' + IntToStr(Count) + '次';
end;
end;
procedure TFormLogin.BtnCancelClick(Sender: TObject);
begin
MyValue := 0;
Close;
end;
procedure TFormLogin.FormShow(Sender: TObject);
begin
self.Caption := MyTitle;
MaskEdit_Pwd.Text := '';
Combo_Name.Clear();
Combo_Name.Items.Add('Guest');
Combo_Name.Items.Add('管理员');
Combo_Name.Text := 'Guest';
LabelWarning.Caption := '请输入用户名和密码(Guest没有密码)';
Count := 0;
end;
procedure TFormLogin.FormCreate(Sender: TObject);
begin
MyTitle := '用户登录';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -