Delphi中InputQuery的改良

今天,我在写程序时想到使用’InputQuery’函数来做一个在应用程序退出之前确认用户身份后方可关闭的过程,但在测试时发现,InputQuery的 编辑框输入不是掩码的,另InputQuery的按键也是英文的,非常不专业!于是我想到改良InputQuery.

你只要将’inputquery改良.dcu文件’文件夹里的Dialogs.dcu和Consts.dcu复制到..\Borland\Delphi7\Lib目录下.重新编译你的程序, 即可!

具体步骤如下:

1>在..\Borland\Delphi7\Source\Vcl目录下找到:Dialogs.pas 和Consts.pas

2>在Dialogs.pas单元中加入代码:

function InputQuery(const ACaption, APrompt: string;
var Value: string): Boolean;
.//省略
with Edit do begin
PasswordChar := ‘*’;//这是加入代码:编辑框掩码
Parent := Form;
Left := Prompt.Left;
Top := Prompt.Top + Prompt.Height + 5;
Width := MulDiv(164, DialogUnits.X, 4);
MaxLength := 255;
//省略

3>修改Consts.pas单元使按钮支持中文

SMsgDlgWarning = ‘Warning’;
SMsgDlgError = ‘Error’;
SMsgDlgInformation = ‘Information’;
SMsgDlgConfirm = ‘Confirm’;
SMsgDlgYes = ‘&Yes’;
SMsgDlgNo = ‘&No’;
SMsgDlgOK = ‘确认’;//确定键
SMsgDlgCancel = ‘取消’;//取消键
SMsgDlgHelp = ‘&Help’;
SMsgDlgHelpNone = ‘No help available’;
SMsgDlgHelpHelp = ‘Help’;
SMsgDlgAbort = ‘&Abort’;
SMsgDlgRetry = ‘&Retry’;
SMsgDlgIgnore = ‘&Ignore’;
SMsgDlgAll = ‘&All’;
SMsgDlgNoToAll = ‘N&o to All’;
SMsgDlgYesToAll = ‘Yes to &All’;

4>最后将重新编译后的Dialogs.dcu和Consts.dcu 复制到..\Borland\Delphi7\Lib 目录下,覆盖原来的Dialogs.dcu和Consts.dcu即可!