Delphi:inputquery,inputbox Usage and differences
function Inputquery (const acaption, aprompt:string; var value:string): Boolean;
The Inputquery return value is the string in which the OK input is placed in the variable value
function InputBox (const acaption, aprompt, adefault:string): string;
The InputBox return value is a string, that is, the input string
Procedure Tform1.button1click (Sender:tobject);
Var
s:string;
Begin
When the OK button is clicked, the
If Inputquery (' title ', ' hint character ', s) then
Begin
If s<> ' then//if the input is not empty
ShowMessage (s);
End
End
Procedure Tform1.button2click (Sender:tobject);
Var
s:string;
Begin
S:=inputbox (' title ', ' hint character ', s);
If S<> ' Then
ShowMessage (s);
End
Delphi customizes the InputBox by customizing the message, enabling it to support the mask and modify the button's caption
First, customize a message ID
Const
Inputboxmessage = Wm_user + 200;
The process of declaring and implementing the message is then
Procedure Inputboxsetpasswordchar (var msg:tmessage); Message inputboxmessage;//Declaration
Procedure Tfrm.inputboxsetpasswordchar (var msg:tmessage);//implementation
Var
Hinputform, Hedit, Hbutton:hwnd;
Begin
Hinputform: = Screen.forms[0]. Handle;
if (hinputform <> 0) Then
Begin
Hedit: = FindWindowEx (hinputform, 0, ' Tedit ', nil);
SendMessage (Hedit, Em_setpasswordchar, Ord (' * '), 0);
Change button text:
Hbutton: = FindWindowEx (hinputform, 0, ' TButton ', ' Cancel ');
SendMessage (Hbutton, wm_settext,0, Integer (PChar (' Cancel ')));
Hbutton: = FindWindowEx (hinputform, 0, ' TButton ', ' OK ');
SendMessage (Hbutton, wm_settext,0, Integer (PChar (' OK ')));
End
End
Using a custom InputBox
PostMessage (Handle, inputboxmessage, 0, 0);
InputBox (' Please set unlock password ', ' please set unlock password (cannot be empty): ', ');
Delphi inputbox,inputquery Usage