What is the difference between TForm.Close and closing with a form?

My application has one main form, and I have a button in this form to close / close the application. It is currently written with a Windows call to close the handle:

SendMessage(Handle, WM_CLOSE, 0, 0); 

But I wonder what harm is in use:

 formName.Close; 

What is the correct use here? Is there a reason to use SendMessage?

+4
source share
1 answer

They do the same thing. In fact, in Forms.pas you will find

 procedure WMClose(var Message: TWMClose); message WM_CLOSE; ... implementation ... procedure TCustomForm.WMClose(var Message: TWMClose); begin Close; end; 

indicating that the WM_CLOSE message simply translates to Self.Close .

Generally, you should use Close if you can, as this is more Delphi-ish and shorter.

+10
source

All Articles