Solved

How to avoid an error from displaying the little windows error box

Posted on 1998-10-04
11
288 Views
Last Modified: 2010-04-06
Hi, I would like to know how to avoid any error messages from displaying the little windows error box? The error
don't came from my code it came from an external event so
the try/except statement doesn't work.
What I would like is that instead of seeing the windows error box, my own error message appear in the Memo of my application.
Thanks.
0
Comment
Question by:mabell
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
You can avoid some of these windows boxes by using win API SetErrorMode.

Does this help?

Regards, Madshi.
0
 
LVL 4

Expert Comment

by:BoRiS
Comment Utility
mabell

here is an example of the API SetErrorMode

var
Errormode : Word;

begin
  ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
//don't forget to set the errormode back to its normal state
fianlly
 SetErrorMode(ErrorMode);

Later
BoRiS
0
 
LVL 1

Expert Comment

by:AndersWP
Comment Utility
mabell, you can also make your own exception handler and let it determine which messages to show and which to suppress.

An exception handler is a procedure of the form

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

You assign it to the Application object's OnException event, and it then gets called every time an exception occurs in stead of the default exception handler. Depending on the type of exception passed in the E parameter you can take different actions, typically displaying or not displaying an error message, stopping or not stopping the program.

Regards,
AndersWP



0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
AndersWP,

you wrote "...instead of the default exception handler...". That is true, but the default exception handler is already a Delphi box, isn't it?
So: Writing an own exception handler is nice, but doesn't suppress the windows error boxes mabell is talking of. Or am I wrong?

Regards, Madshi.
0
 
LVL 1

Expert Comment

by:AndersWP
Comment Utility
You are right Madshi, an exception handler will only catch those error messages that are shown as Delphi error boxes. BTW, which errors are not? I can think of the 'illegal instruction' error; are there others?

Regards,
AndersWP
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 20

Expert Comment

by:Madshi
Comment Utility
AndersWP,

yes, there are other (quite normal) windows error boxes. Look at SetErrorMode. I don't remember any examples right now, but there are some...

Regards, Madshi.
0
 

Author Comment

by:mabell
Comment Utility
Thanks all, but can you tell me more info about the SetErrorMode
api like where I put this in my code, what is that value:
SEM_FailCriticalErrors, etc.
You can also give me a web site who give me this type of information.
Thanks.
0
 

Author Comment

by:mabell
Comment Utility
Thanks all, but can you tell me more info about the SetErrorMode
api like where I put this in my code, what is that value:
SEM_FailCriticalErrors, etc.
You can also give me a web site who give me this type of information.
Thanks.
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
I don't have a website. These apis are just described in the win32.help file...
I'm calling "SetErrorMode(SEM_FAILCRITICALERRORS or SEM_NOOPENFILEERRORBOX)" in the beginning of each and every of my programs. Perhaps it's not the way Microsoft has it planned - but I just don't want windows error boxes!

Regards, Madshi.

0
 
LVL 4

Expert Comment

by:BoRiS
Comment Utility
mabell

Here is a snippet I used to check if the disk is in drive A:

function DiskInDrive(Drive: Char): Boolean;
var
  ErrorMode: word;
begin
  { make it upper case }
  if Drive in ['a'..'z'] then Dec(Drive, $20);
  { make sure it's a letter }
  if not (Drive in ['A'..'Z']) then
    raise EConvertError.Create('Not a valid drive ID');
  { turn off critical errors }
  ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
  try
    { drive 1 = a, 2 = b, 3 = c, etc. }
    if DiskSize(Ord(Drive) - $40) = -1 then
      Result := False
    else
      Result := True;
  finally
    { restore old error mode }
    SetErrorMode(ErrorMode);
  end;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
 DiskinDrive(Key);
end;

Here I do the check, hide windows error, display mine etc.

As for the web site I'm not sure windows api stuff is not found that often on the web...

Later
BoRiS
0
 

Accepted Solution

by:
smartass earned 50 total points
Comment Utility
The answer to your original q is easy (I think if I'm understanding it right?) in the menu tools enviromental options you should simply uncheck the break on exception box and delphi won't break on exceptions (wow that sounds really inteligent but hey it works)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now