Tutorial :MessageBox



Question:

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


Solution:1

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).


Solution:2

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


Solution:3

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.


Solution:4

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


Solution:5

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.


Solution:6

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".


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »