Delphi: inputquery, inputbox usage and Difference
Function inputquery (const acaption, aprompt: string; VaR value: string): Boolean;
The return value of inputquery is whether the string entered with OK is placed in the variable value.
Function inputbox (const acaption, aprompt, adefault: string): string;
The return value of inputbox is a string, that is, the input string.
Procedure tform1.button1click (Sender: tobject );
VaR
S: string;
Begin
// After clicking the OK button
If inputquery ('title', 'character prompting ', 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', 'character prompting ', S );
If S <> ''then
Showmessage (s );
End;
Delphi uses a custom message to customize the inputbox to enable it to support the mask and modify the caption of the button
First, define a Message ID.
Const
Inputboxmessage = wm_user+ 200;
Then declare and implement the message processing process.
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: = finddomainwex (hinputform, 0, 'tedit ', nil );
Sendmessage (hedit, em_setpasswordchar, ord ('*'), 0 );
// Change button text:
Hbutton: = find1_wex (hinputform, 0, 'tbutton', 'cancel ');
Sendmessage (hbutton, wm_settext, 0, INTEGER (pchar ('cancel ')));
Hbutton: = find1_wex (hinputform, 0, 'tbutton', 'OK ');
Sendmessage (hbutton, wm_settext, 0, INTEGER (pchar ('OK ')));
End;
End;
Use the custom inputbox
postmessage (handle, inputboxmessage, 0, 0);
inputbox ('set the unlock password', 'set the unlock password (cannot be blank ):', '');