//判断是否是第一次使用
function Wsz_IfFirst:Boolean;
var
sUser:string;
sPass:string;
begin
result := false;
RegF:=TRegistry.Create;
RegF.RootKey :=HKEY_LOCAL_MACHINE;
RegF.OpenKey("SOFTWARE\MicroSoft\whh726",TRUE);
sUser := RegF.ReadString("user");
sPass := RegF.ReadString("pass");
if ((length(sUser)<=0) and (length(sPass)<=0)) then
result := true ;
RegF.Free;
end;
file://判断用户名和口令是否正确
function Wsz_CheckUser(MyUser:string;MyPass :string):Boolean;
var
sUser:string;
sPass:string;
begin
result:= false;
RegF:=TRegistry.Create;
RegF.RootKey :=HKEY_LOCAL_MACHINE;
RegF.OpenKey("SOFTWARE\MicroSoft\whh726",TRUE);
sUser := RegF.ReadString("user");
sPass := RegF.ReadString("pass");
if (sUser=MyUser) and (sPass=MyPass) then
result := true;
RegF.Free;
end;
file://保存用户名和口令
procedure Wsz_SaveUser(MyUser:string;MyPass :string);
begin
RegF:=TRegistry.Create;
RegF.RootKey :=HKEY_LOCAL_MACHINE;
RegF.OpenKey("SOFTWARE\MicroSoft\whh726",TRUE);
RegF.WriteString("user",MyUser);
RegF.WriteString("pass",MyPass);
RegF.Free;
end;
file://取消按纽事件
procedure TWszLoginForm.BitBtnCloseClick(Sender: TObject);
begin
Close;
end;
file://确定按纽事件
procedure TWszLoginForm.BitBtnYesClick(Sender: TObject);
var
suser:string;
spass:string;
begin
suser := trim(edituser.text);
spass := trim(editpass.text);
if (length(suser)<=0) or (length(spass)<=0) then
begin
Application.MessageBox("用户名和口令都必须输入!",
"系统提示",
MB_OK + MB_ICONINFORMATION);
edituser.SetFocus ;
exit;
end;
if Wsz_IfFirst then
begin
file://处理第一次登录的用户名和口令
if Application.MessageBox(
"您是第一次使用本软件,请记住您的用户名和口令,
以便下次登录。现在进入系统吗?",
"系统提示",
MB_OKCANCEL + MB_ICONQUESTION) = IDOK then
begin
file://保存
Wsz_SaveUser(suser,spass);
end
else
begin
edituser.SetFocus ;
exit;
end;
end else
begin
if not Wsz_CheckUser(suser,spass) then
begin
Application.MessageBox
("对不起,用户名和口令输入不正确!", "系统提示",
MB_OK + MB_ICONINFORMATION);
edituser.setfocus ;
exit;
end;
end;
file://全局变量
GB_Wsz_User := suser;
GB_Wsz_PASS := spass;
Close;
end;
file://窗体的Show事件
procedure TWszLoginForm.FormShow(Sender: TObject);
begin
if Wsz_IfFirst then
begin
Application.MessageBox(
"您是第一次使用本软件,您可以随便输入用户名和口令。",
"系统提示",
MB_OK + MB_ICONINFORMATION);
end;
end;
本文来源:不详 作者:佚名