在用InputBox这个函数的时候  我怎么才能判断用户按的是Yes还是Cannel呀
str:=InputBox('输入','输入名称','name');
当str的值是name的时候  我怎么判断用户按的是哪个按钮

解决方案 »

  1.   

    Use the InputBox function when there is a default value that should be used when the user chooses the Cancel button (or presses Esc) to exit the dialog. If the application needs to know whether the user chooses OK or Cancel, use the InputQuery function instead.
    InputBox不能判断用户按的是哪个按钮,但如果按的是Cancel,返回的一定是默认值。如果要知道用户按的哪个按钮,用InputQuery()。function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;ACaption is the caption of the dialog box.APrompt is the text that prompts the user to enter input in the edit box.Value is the string that appears in the edit box when the dialog box first appears and which returns the value that the user enters.(默认值,如果用户输入了,就是返回值)InputQuery returns True if the user chooses OK, and False if the user chooses Cancel or presses the Esc key.(此函数如果返回True,就是OK,否则是False)
      

  2.   

    If the application needs to know whether the user chooses OK or Cancel, use the InputQuery function instead你想知道用户按的是ok还是cancel就用InputQuery这个函数来代替InputBox这个函数。
      

  3.   

    var
      Form1: TForm1;
      ok:boolean;
      str:string;
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
     ok:=InputQuery('輸入','輸入名稱  :  ',str);
     if ok then
     showmessage('ok')
     else
     showmessage('no');
    end;