Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect close form from border icon?

I've got Cancel and OK buttons in my form. They both do something and then call close form. How can I make the [x] button on form to call the Cancelclick?

like image 689
JustMe Avatar asked Dec 02 '22 02:12

JustMe


2 Answers

If the form is shown modally then you just need to test the value of ModalResult. A value of mrCancel indicates that the cross was clicked.

I would be inclined to arrange that your buttons used their ModalResult properties to effect closing of the form. Set the OK button's ModalResult to mrOK and that for the cancel button to mrCancel.

like image 182
David Heffernan Avatar answered Dec 20 '22 07:12

David Heffernan


Add this to your form's public declaration

procedure WMSysCommand(var MSG: TWMSysCommand); message WM_SYSCOMMAND;

then add the method

procedure TForm1.WMSYSCommand(var MSG:  TWMSysCommand);
begin
  if MSG.CmdType = SC_CLOSE then
  begin
     //Closing from border icon
  end;
  inherited;
end;
like image 32
A Lombardo Avatar answered Dec 20 '22 06:12

A Lombardo