設計流程為
在Delphi開發環境中
增加函數Wsz_IfFirst
//判斷是否是第一次使用
function Wsz_IfFirst:Boolean;
var
sUser:string;
sPass:string;
begin
result := false;
RegF:=TRegistryCreate;
RegFRootKey :=HKEY_LOCAL_MACHINE;
RegFOpenKey( SOFTWARE\MicroSoft\whh TRUE);
sUser := RegFReadString( user );
sPass := RegFReadString( pass );
if ((length(sUser)<=) and (length(sPass)<= )) then
result := true ;
RegFFree;
end;
file://判斷用戶名和口令是否正確
function Wsz_CheckUser(MyUser:string;MyPass :string):Boolean;
var
sUser:string;
sPass:string;
begin
result:= false;
RegF:=TRegistryCreate;
RegFRootKey :=HKEY_LOCAL_MACHINE;
RegFOpenKey( SOFTWARE\MicroSoft\whh TRUE);
sUser := RegFReadString( user );
sPass := RegFReadString( pass );
if (sUser=MyUser) and (sPass=MyPass) then
result := true;
RegFFree;
end;
file://保存用戶名和口令
procedure Wsz_SaveUser(MyUser:string;MyPass :string);
begin
RegF:=TRegistryCreate;
RegFRootKey :=HKEY_LOCAL_MACHINE;
RegFOpenKey( SOFTWARE\MicroSoft\whh TRUE);
RegFWriteString( user MyUser);
RegFWriteString( pass MyPass);
RegFFree;
end;
file://取消按紐事件
procedure TWszLoginFormBitBtnCloseClick(Sender: TObject);
begin
Close;
end;
file://確定按紐事件
procedure TWszLoginFormBitBtnYesClick(Sender: TObject);
var
suser:string;
spass:string;
begin
suser := trim(editusertext);
spass := trim(editpasstext);
if (length(suser)<=) or (length(spass)<= ) then
begin
ApplicationMessageBox( 用戶名和口令都必須輸入!
系統提示
MB_OK + MB_ICONINFORMATION);
edituserSetFocus ;
exit;
end;
if Wsz_IfFirst then
begin
file://處理第一次登錄的用戶名和口令
if ApplicationMessageBox(
您是第一次使用本軟件 請記住您的用戶名和口令
以便下次登錄現在進入系統嗎?
系統提示
MB_OKCANCEL + MB_ICONQUESTION) = IDOK then
begin
file://保存
Wsz_SaveUser(suserspass);
end
else
begin
edituserSetFocus ;
exit;
end;
end else
begin
if not Wsz_CheckUser(suserspass) then
begin
ApplicationMessageBox
(對不起 用戶名和口令輸入不正確! 系統提示
MB_OK + MB_ICONINFORMATION);
editusersetfocus ;
exit;
end;
end;
file://全局變量
GB_Wsz_User := suser;
GB_Wsz_PASS := spass;
Close;
end;
file://窗體的Show事件
procedure TWszLoginFormFormShow(Sender: TObject);
begin
if Wsz_IfFirst then
begin
ApplicationMessageBox( 您是第一次使用本軟件 您可以隨便輸入用戶名和口令 系統提示
MB_OK + MB_ICONINFORMATION);
end;
end;
From:http://tw.wingwit.com/Article/os/xtgl/201311/9467.html