Delphi 7 - how to use Inputbox

15,388

InputBox() returns a blank string if the dialog is canceled, eg:

var
  Pass: String;

Pass := InputBox('Password needed', 'Enter the password:');
if Pass <> '' then
begin
  // use Pass as needed...
end;

Alternatively, use InputQuery() instead, which returns a Boolean to indicate whether the dialog was canceled or not, eg:

var
  Pass: String;

if InputQuery('Password needed', 'Enter the password:', Pass) then
begin
  // use Pass as needed...
end;
Share:
15,388
0x436f72647265
Author by

0x436f72647265

Windows App developer. C#, C++/C, .Net

Updated on June 04, 2022

Comments

  • 0x436f72647265
    0x436f72647265 almost 2 years

    I am programming a program where you have to enter a password into a InputBox to gain access to the programs min features . But I have a problem if you click on cancel on the inputbox my program gives a error message . So i wanted to know if any one know how I can get that right because with the Messagedlg I know you use IF . But how can I get it right with a InputBox ?

  • 0x436f72647265
    0x436f72647265 almost 11 years
    @Remy_Lebeau Thanks for the help I will go and try that. I have 1 more question do you maby know how to make a Input Box masked ?? I know what to change but do I need to write a knew InputBox Function??
  • bummi
    bummi almost 11 years
    @CordreSmith about masking te input box stackoverflow.com/q/591333/1699210
  • Freddie bell
    Freddie bell over 10 years
    Passing #31+'Enter the password' as the 2nd parameter to InputQuery causes the TEdit in the box to echo the password character instead of the entered text.
  • Remy Lebeau
    Remy Lebeau over 10 years
    @Freddiebell: Any value below #32 will cause the TEdit.PasswordChar to be set to '*'. However, that feature was introduced in XE2, so it does not exist in D7.