Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between TForm.Close and closing via a form's handle?

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?

like image 627
Aaron Avatar asked Dec 21 '22 09:12

Aaron


1 Answers

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.

like image 81
Andreas Rejbrand Avatar answered Dec 24 '22 00:12

Andreas Rejbrand