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?
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
.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With