My application has one main form and I have a button on that form to close/exit the application. Currently it's written with a call to Windows to close the handle:
SendMessage(Handle, WM_CLOSE, 0, 0);
But I'm wondering what's the harm in using:
formName.Close;
What's the proper usage here? Is there any reason to use the SendMessage?
They do exactly the same thing. In fact, in Forms.pas
you find
procedure WMClose(var Message: TWMClose); message WM_CLOSE;
...
implementation
...
procedure TCustomForm.WMClose(var Message: TWMClose);
begin
Close;
end;
showing that the WM_CLOSE
message simply translates to Self.Close
.
Generally, you should use Close
if you can, since that is more Delphi-ish and shorter.
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