암호 입력을위한 Delphi Inputbox?
문제
입력 상자 :
answer:=Inputbox('a','b','c');
잘 작동하지만 타이핑 된 캐릭터 대신 작은 별 만 볼 수있는 암호 상자와 같이 마스킹 된 하나를 찾고 있습니다.
해결책
생성 된 편집 컨트롤로 Windows 메시지를 보낼 수 있습니다. InputBox
, 비밀번호 입력의 편집 컨트롤을 표시합니다. 아래 코드에서 가져온 코드 http://www.swissdelphicenter.ch/en/showcode.php?id=1208:
const
InputBoxMessage = WM_USER + 200;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure InputBoxSetPasswordChar(var Msg: TMessage); message InputBoxMessage;
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.InputBoxSetPasswordChar(var Msg: TMessage);
var
hInputForm, hEdit, hButton: HWND;
begin
hInputForm := Screen.Forms[0].Handle;
if (hInputForm <> 0) then
begin
hEdit := FindWindowEx(hInputForm, 0, 'TEdit', nil);
{
// Change button text:
hButton := FindWindowEx(hInputForm, 0, 'TButton', nil);
SendMessage(hButton, WM_SETTEXT, 0, Integer(PChar('Cancel')));
}
SendMessage(hEdit, EM_SETPASSWORDCHAR, Ord('*'), 0);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
InputString: string;
begin
PostMessage(Handle, InputBoxMessage, 0, 0);
InputString := InputBox('Input Box', 'Please Enter a Password', '');
end;
다른 팁
XE2에서 InputBox()
그리고 InputQuery()
마스킹을 기본적으로 지원하도록 업데이트되었습니다 TEdit
입력, 해당 기능은 아직 문서화되지 않았습니다. 첫 번째 캐릭터 인 경우 APrompt
매개 변수는 모든 값으로 설정됩니다 #32
그럼 TEdit.PasswordChar
설정됩니다 *
, EG :
answer := InputBox('a', #31'b', 'c');
입력 상자는 대화 상자에서 입력 query 함수를 호출하여 양식을 동적으로 만듭니다. 항상이 기능의 사본을 만들고 Tedit의 PasswordChar 속성을 변경할 수 있습니다.
나는 델파이가 그런 것들을 상자에 포함한다고 생각하지 않습니다. 어쩌면 당신은 하나를 찾을 수 있습니다 http://www.torry.net/ 또는 그물의 다른 곳. 그렇지 않으면 스스로를 직접 쓰십시오. 그렇게 어렵지 않아야합니다. :-) "충분히 큰"델파이 버전이있는 경우 소스 코드를 볼 수도 있습니다.
울리.
입력 상자 대신 InputQuery를 사용할 수 있습니다. 진정한 인수가 설정되면 암호 필드가 마스크됩니다.
InputQuery('Authenticate', 'Password:',TRUE, value);
여기에 일부 자원; http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/inputquery.html