Welcome

首页 / 软件开发 / Delphi / 第十章-动态链接库编程(二)(3)

第十章-动态链接库编程(二)(3)2007-05-07在口令设置窗口中,为了确保用户记住了设置的口令,在用户输入并按回车键后,要求用户再次输入进行确认。只有用户重新输入的字符串与原设置口令相同,口令设置窗口才能正常关闭 。否则将原设置口令清空,要求用户再次输入。以上功能的实现在编辑框的OnKeyPress事件处理过程中。

procedure TSetPassWordForm.Edit1KeyPress(Sender: TObject; var Key: Char);

begin

if Edit1.text = "" then Exit;

if Key = #13 then

begin

if Verified then

if StrPas(PassWord) = Edit1.text then

begin

OKBtn.Enabled := True;

Edit1.Enabled := False;

OKBtn.SetFocus;

end

else

begin

Verified := False;

MessageDlg("PassWord is InValid.",mtWarning,[mbOK],0);

Edit1.text := "";

PassWord := "";

Label1.Caption := "Please Input PassWord:";

end

else

begin

Verified := True;

StrPCopy(PassWord,Edit1.text);

Edit1.text := "";

Label1.caption := "Please Verify PassWord:";

end;

Key := #0;

end;

end;

口令检查窗口的实现相对简单,只定义了一个输出函数GetPassWord,用于生成口令检查窗口并返回口令检查的结果。

function GetPassword(Password: PChar): Boolean;

var

GetPasswordForm: TGetPasswordForm;

begin

Result := False;

GetPasswordForm := TGetPasswordForm.Create(Application);

try

with GetPasswordForm do

if ShowModal = mrOK then

if UpperCase(Edit1.Text) <> StrPas(StrUpper(Password)) then

MessageDlg("Invalid Password", mtWarning, [mbOK], 0)

else

Result := True;

finally

PasswordForm.Free;

end;

end;

PassWord为输入的参数,不能为空,由调用以上函数的程序负责维护。

窗口中用户输入口令时回显在屏幕上的字符由编辑框的PassWordChar属性确定。

在DLLs的工程文件中,把两个输出函数写到exports子句中。

library PassForm;

uses

GetPass in "GETPASS.PAS" {PasswordForm},

Setpass in "SETPASS.PAS" {SetPassWordForm};

exports

GetPassword,SetPassWord;

begin

end.