Solved

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

Posted on 1998-10-04
11
294 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 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