InputBox 問い合わせ

InputBox関数は文字列入力用のダイアログを表示します。Delphiにも同名の InputBox関数がありますがこの関数はユーザーが[OK] を押したか[Cancel] を押したかが解りません。知る必要がある場合は InputQuery関数を使用します。この関数は[OK] を押されれば Trueを、[Cancel] を押されれば Falseを返します。

■ InputBox、InputQueryの例
procedure TForm1.Button1Click(Sender: TObject);
var
  s : string;
begin
  //InputBoxの例
  s :=  InputBox('名前入力', 'お名前は?', '名無しの権兵衛');
  ShowMessage(S + 'さんですね');

  //InputQueryの例
  if  InputQuery('名前入力', 'お名前は?', s)  then  begin
    {[OK]をクリックした場合}
    ShowMessage(S + 'さんですね');
  end else begin
    {[キャンセル]をクリックした場合}
    ShowMessage('中止します');
  end;
end;