Ken Byington
Ken Byington

Reputation: 160

Prevent Delphi COM component from showing MessageBox()

We have a Delphi 2007 COM component being executed from an ISAPI app. The COM component is hanging the app because it is attempting to display a MessageBox(). The call to MessageBox() must be occurring in the Delphi RTL becase it is not in our user code.

The app hangs, of course, because there is no one logged in at the server to clear the MessageBox().

How do we configure our Delphi project so that the Delphi RTL does not attempt to display MessageBox() on exception?

Upvotes: 4

Views: 1423

Answers (5)

Toby Allen
Toby Allen

Reputation: 11213

Is it possible to compile the application as a Console app? I'm not sure if you can do this and still have it contain COM object, this would prevent message dialogs from being shown I'm sure.

Just a thought.

Upvotes: 0

André
André

Reputation: 9112

I've created a unit to hook MessageBox/MessageDlg calls (via detouring), so I can suppress these calls in a Windows Service (to avoid "hanging" of my service dll because of some stupid code of someone else with a messagebox call in it). If you want it, I can search this unit and send it to you.

Upvotes: -1

Mason Wheeler
Mason Wheeler

Reputation: 84550

Write your own exception handler and attach it to the Application.OnException event. If an OnException event handler is present, Application won't use its default MessageBox routine. The signature is defined as:

TExceptionEvent = procedure (Sender: TObject; E: Exception) of object;

If this is a server, you'll probably want to write the exception information to a log, and possibly return some error to the user.

Upvotes: 3

Jim
Jim

Reputation: 4711

What does the messagebox say? I'm assuming it's an exception. Why don't you put an exception handler around the code in the COM component, and log the exception in a different way? (E.g., using the Event Log). And/or fix the problem that's leading to the exception in the first place.

Upvotes: 2

Yogi Yang 007
Yogi Yang 007

Reputation: 5251

I don't know of any direct way in Delphi but what you can do is write a small script in AutoIT/AutoHotKey and keep that script running in system tray, so that it will automatically close the MessageBox.

Believe me it is very simple.

http://www.autoitscript.com/autoit3/index.shtml

http://www.autohotkey.com/

HTH

Upvotes: 1

Related Questions