在OnCloseQuery事件中 if messagedlg('您要关闭文件吗?',mtconfirmation,[mbyes,mbno],0)<>idyes then ....
if messagedlg('您要关闭文件吗?',mtconfirmation,[mbyes,mbno],0)<>idyes then Action:=caNone ;Action的值: Value MeaningcaNone The form is not allowed to close, so nothing happens. caHide The form is not closed, but just hidden. Your application can still access a hidden form. caFree The form is closed and all allocated memory for the form is freed. caMinimize The form is minimized, rather than closed.To close the form and free it in an OnClose event, set Action to caFree.
上面的写在窗体的onclose事件中
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
if messagedlg('您要关闭文件吗?',mtconfirmation,[mbyes,mbno],0)<>idyes then
....
Action:=caNone ;Action的值:
Value MeaningcaNone The form is not allowed to close, so nothing happens.
caHide The form is not closed, but just hidden. Your application can still access a hidden form.
caFree The form is closed and all allocated memory for the form is freed.
caMinimize The form is minimized, rather than closed.To close the form and free it in an OnClose event, set Action to caFree.