Delphi 7 - how to use Inputbox

强颜欢笑 提交于 2019-12-10 18:05:55

问题


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 ?


回答1:


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;


来源:https://stackoverflow.com/questions/16830562/delphi-7-how-to-use-inputbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!