首页 / 软件开发 / Delphi / 第十章-动态链接库编程(二)(3)
第十章-动态链接库编程(二)(3)2007-05-07在口令设置窗口中,为了确保用户记住了设置的口令,在用户输入并按回车键后,要求用户再次输入进行确认。只有用户重新输入的字符串与原设置口令相同,口令设置窗口才能正常关闭 。否则将原设置口令清空,要求用户再次输入。以上功能的实现在编辑框的OnKeyPress事件处理过程中。 procedure TSetPassWordForm.Edit1KeyPress(Sender: TObject; var Key: Char);beginif Edit1.text = "" then Exit;if Key = #13 thenbeginif Verified thenif StrPas(PassWord) = Edit1.text thenbeginOKBtn.Enabled := True;Edit1.Enabled := False;OKBtn.SetFocus;endelsebeginVerified := False;MessageDlg("PassWord is InValid.",mtWarning,[mbOK],0);Edit1.text := "";PassWord := "";Label1.Caption := "Please Input PassWord:";endelsebeginVerified := True;StrPCopy(PassWord,Edit1.text);Edit1.text := "";Label1.caption := "Please Verify PassWord:";end;Key := #0;end;end;口令检查窗口的实现相对简单,只定义了一个输出函数GetPassWord,用于生成口令检查窗口并返回口令检查的结果。 function GetPassword(Password: PChar): Boolean;varGetPasswordForm: TGetPasswordForm;beginResult := False;GetPasswordForm := TGetPasswordForm.Create(Application);trywith GetPasswordForm doif ShowModal = mrOK thenif UpperCase(Edit1.Text) <> StrPas(StrUpper(Password)) thenMessageDlg("Invalid Password", mtWarning, [mbOK], 0)elseResult := True;finallyPasswordForm.Free;end;end;PassWord为输入的参数,不能为空,由调用以上函数的程序负责维护。窗口中用户输入口令时回显在屏幕上的字符由编辑框的PassWordChar属性确定。在DLLs的工程文件中,把两个输出函数写到exports子句中。 library PassForm; usesGetPass in "GETPASS.PAS" {PasswordForm},Setpass in "SETPASS.PAS" {SetPassWordForm}; exportsGetPassword,SetPassWord; beginend.