11 Vote

Delphi: ShowMessage with User Input

Tip by Progger99 | 2012-04-29 at 22:11

Today I have a little tip for all users of Delphi. It's about two ways to get and process user input easily and quickly:

procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
begin
  // first possibility
  repeat
    s := InputBox('title', 'text', 'start text');
  until s <> '';
 
  // second possibility
  if InputQuery('title', 'text', s)
  then ShowMessage('It was not canceled.');
end;

First possibility: The function InputBox opens much like a normal ShowMessage, with the only difference, that a user input is possible. As a parameter, you can pass a caption (in the example "title"), a text to be displayed in the box and a default starting value for the user input. Then, InputBox returns the string, the user typed in. In the example above, we are calling InputBox as long until the returned string is not empty.

Second possibility: InputQuery behaves much like InputBox. But this time, the return value is true or false, depending on whether the user clicked OK or Cancel in the dialog. Again, we can specify a title and a text for the box. The third parameter is a string, which is also the initial value of the box and after the call, this variable also contains the value entered by the user.

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

Delphi: System-Wide HotKey

Tutorial | 1 Comment

PHP: Sending an E-Mail

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.