请讲讲Form的CanClose属性?它是form的属性吗?

解决方案 »

  1.   

    Use OnCloseQuery to specify the conditions under which the form can close. An OnCloseQuery event handler contains a Boolean CanClose variable that determines whether a form is allowed to close. Its default value is True. You can use an OnCloseQuery event handler to ask users if they are sure they really want the form closed immediately. For example, you can use the handler to display a message box that prompts the user to save a file before closing the form.The TCloseQueryEvent type points to the method that determines whether a form can be closed. The value of the CanClose parameter determines if the form can close or not.
      

  2.   

    不是属性,是OnCloseQuery事件的一个参数
      

  3.   

    CanClose不是属性,Form没有有CanClose属性。
    CanClose在From.FormCloseQuery里出现:From.FormCloseQuery(Sender: TObject; var CanClose: Boolean);作用是阻止窗口的关闭——将CanClose设置为否(CanClose := False)。
    当窗体要关闭的时候(可以是用代码关闭,也可以是点窗体的关闭按钮)可以用它阻止窗体的关闭,并可以写些代码提示用户应该做什么事情,或者执行其他代码。总之当你不希望这个窗体在特定时刻关闭时,用它。
    注意要是不进行判断而总是设置为False,窗体将不能被关闭,除非强行结束它的进程。
    具体的可以参看Delphi的Forms单元,里面有详细的代码。
      

  4.   

    TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      if messagebox(handle,'确认关闭吗?','警告',MB_YESNO)=ID_NO then
        canclose := false;
    end