各位版主:
      请问在Delphi中编写主界面,当程序运行后要退出程序点击主界面右上角的"X"按钮时要出现:提示框是(Y)和否(N)按钮,该如何编写代码?请提供代码.

解决方案 »

  1.   

    procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    begin
      if MessageBox(handle,'您确定要退出吗?','退出系统',MB_YESNO+MB_ICONQUESTION) = IDYES then
      canclose:= true else canclose:= false;
    end;
      

  2.   

    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
       case Application.MessageBox('确定要退出吗?', '系统提示', MB_YESNO + MB_ICONQUESTION) of
         IDYES: ;
         IDNO: Action := caNone;
       end;end;
      

  3.   

    这样的窗口本来要ShowModal出来的....才可以用楼上的方法
      

  4.   

    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
       case Application.MessageBox('确定要退出吗?', '系统提示', MB_YESNO + MB_ICONQUESTION) of
         IDYES: ;
         IDNO: Action := caNone;
       end;end;
      

  5.   

    怎么会呢?这是form的OnCloseQuery事件啊,你别自己写这个函数啊
      

  6.   

    我也不知道上面的行不行???
    拦截WM_CLOSE消息吧
    代码如下:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
      private
        { Private declarations }
      public
        procedure lanjie(var tt:Tmsg); message WM_CLOSE;
      end;var
      Form1: TForm1;implementation{$R *.dfm}
       procedure TForm1.lanjie(var  tt:Tmsg);
          begin
            case  Application.MessageBox('你确定要退出吗?','提示',MB_YESNO) of
               IDYES:Application.Terminate;
               IDNO:;
            end;
          end;
    end.
    以上代码在Delphi7中编译运行正确,达到你描述的目的了,去试试吧~~~~~~~~~~~~~!!!!!