Solved

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

Posted on 1998-10-04
11
296 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
ID: 1341771
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
ID: 1341772
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
ID: 1341773
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 20

Expert Comment

by:Madshi
ID: 1341774
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
ID: 1341775
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1341776
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
ID: 1341777
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
ID: 1341778
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
ID: 1341779
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
ID: 1341780
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
ID: 1341781
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

837 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