views:

669

answers:

6
Q: 

MessageBox

In Delphi; what are the differences between Application.MessageBox, Windows.MessageBox or Dialogs.MessageDlg? Or which is more efficient to use computer memory?

+1  A: 

Why do you care about the tiny amount of memory used by a message box? There are many other things you should be concerning yourself with when writing a Delphi app. In any case, as far as I'm aware these are all thin wrappers around the Windows MessageBox API.

anon
Just I was wondering. I use a MessageBox function hundreds of times in one project.
SimaWB
the memory is reclaimed each time the message box closes
anon
@Neil: We will hope so. Seriously if it wasn't reclaimed it would have been detected years ago.
sharptooth
*All* wrappers - not really, see my answer. :-)
Ulrich Gerhardt
A: 

They all do the same - invoke WinAPI function MessageBox(). The difference in resource consumption if any is minimal. If you care so much you can call MessageBox() directly - just include "uses Windows".

sharptooth
*All* wrappers - not really, see my answer. :-)
Ulrich Gerhardt
+9  A: 

Windows.MessageBox is the WinAPI MessageBox, Application.MessageBox is a wrapper around it. Dialogs.MessageDlg however is a VCL form. So if you are concerned about memory or thread safety, the first two might be better suited. MessageDlg OTOH is more flexible and easier to use (IMHO, of course).

Ulrich Gerhardt
+2  A: 

Windows MessageBox is localized by OS (Yes, No, Cancel...), MessageDlg can be localized by hand.

DiGi
Could you provide information how to localize MessageDlg ?
mt_serg
A: 

If I remember correctly, there is one important distinction bewteen the Delphi VCL message boxes and the Windows ones - you can specifiy flags that stop the Application messages from being serviced (eg MB_SYSTEMMODAL). This can be useful for displaying errors where you need to 'freeze' your application - the Delphi MessageDlg will still fire timer events even whilst on screen. See:

MSDN MessageBox stuff

Brian Frost
A: 

Memory usage shouldn't be such a problem with message boxes. I personally prefer the VCL form (Dialogs.MessageBox) since I can localize it from the Consts.pas unit. I also like it from the fact that I can add custom controls to it, like checkboxes for "don't show this again" and other stuff like this.