Solved

Stop Program Popup Errors and exceptions

Posted on 2004-04-27
36
224 Views
Last Modified: 2010-04-05
Hi all,

I'm writing a program that does everything on timer basis.
And the program will be sitting on the windows tray, unattended.
When there is an error, i get a popup message, instead i want it to write the error on a memo.
I've tried:

Try...

execpt... etc...

and also the windows critical error stopping function, but i still get a popup.

How can i stop this?  And i mean with any exception or error?

Thanks

SFern.
0
Comment
Question by:sfern
  • 21
  • 14
36 Comments
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
override the Applications.OnExeception and

Write it out to your memo

protected
 procedure DisplayExceptions(Sender: TObject; E: Exception);


 procedure TForm1.DisplayExceptions(Sender: TObject; E: Exception);
 begin
 Memo1.Lines.Add(E.Message);
 end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Application.OnExeception:= DisplayExceptions;
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility


or get madExcept at www.madshi.net

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
0
 
LVL 12

Expert Comment

by:esoftbg
Comment Utility
try
// ..........
except
  on e : exception do
    Memo1.Add(e.Message);
end;

You will get a popup only when run your application under Delphi IDE. When you run it by the .exe file, you will don't get a popup exception....
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
i didn't mean to say - "override" the Applications.OnExeception, i meant to say

Assign your own  method to the Applications.OnException


This works great,, cause it prevents you from having to place try ... except blocks everywhere in you program,

its global and will catch them all....

Shane
0
 

Author Comment

by:sfern
Comment Utility
If trying the first example but i get:

Undeclared identifier OnExeception :(

What i'm i doing wrong, i'm i putting the Protected in the wrong place?

Thanks
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  protected
   procedure DisplayExceptions(Sender: TObject; E: Exception);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DisplayExceptions(Sender: TObject; E: Exception);
begin
 Memo1.Lines.Add(E.Message);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Application.OnException:= DisplayExceptions;
end;

end.
0
 

Author Comment

by:sfern
Comment Utility
I'm getting the same error, does it require an addition in the uses section?

this is how it looks:
.....

 private
    { Private declarations }
    procedure AddToListView(Value, From: string);
    procedure ToggleStatus(const Status: Boolean);

  public
    { Public declarations }

  protected
  procedure DisplayExceptions(Sender: TObject; E: Exception);
......

implementation

{$R *.dfm}

procedure TOBJ_MainForm.DisplayExceptions(Sender: TObject; E: Exception);
 begin
 Memo1.Lines.Add(E.Message);
 end;

.......


procedure TOBJ_MainForm.FormCreate(Sender: TObject);
begin
Application.OnExeception:= DisplayExceptions;

SendingMail:=False; //Set SendingMail to False
Statusbar1.Panels[1].text := ('Disconnected');

If POP.Connected then
POP.Disconnect;


if Win32Platform = VER_PLATFORM_WIN32_NT then
    Font.Name := 'MS Shell Dlg 2'
  else
    Font.Name := 'MS Shell Dlg';
end;

.....


I'm getting 2 errors:

Undeclared identifier OnExeception

and

Not enough actual parameters.

What i'm i doing wrong?

Thanks




0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
hmmm, what version of delphi are you using....

SHane

0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
Try creating a blank application and try pluggin in my code and see what you get

SHane
0
 

Author Comment

by:sfern
Comment Utility
OK, thanks, i have to try it a bit later though, from home.

I'll let you know later..thanks :)

0
 

Author Comment

by:sfern
Comment Utility
Cannot get it to work, same errors :(

Any ideas?

Thanks
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
Again, what version of delphi????

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
and did you create a blank application?

Shane
0
 

Author Comment

by:sfern
Comment Utility
yes :(

I'm using delphi 6 Ent
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
k, open up help, search for TApplication, and look at its events

You should see OnException

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
Let me know if you find it?

Shane
0
 

Author Comment

by:sfern
Comment Utility
Ok, i tried again and managed to make it work on a new application but for some reason the

formcreate section gives me those errors

Very strange :(
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
hmmm - in your application , or in the new blank application.

Cause i dont get any errors in my Form Create

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
you can actually place it anywhere you like - but the higher up the ladder, the more likely you are to miss exceptions  - thats why i suggest in the form create. You could also assign it in the form's onActivate

or .... in the project source, but since you will be writing your exceptions to a tmemo, you will want it in the main form.

Shane


0
 

Author Comment

by:sfern
Comment Utility
This part gives me the errors, the rest are accepted.

procedure TOBJ_MainForm.FormCreate(Sender: TObject);
begin
Application.OnExeception:= DisplayExceptions;  // <---This line !!!

SendingMail:=False; //Set SendingMail to False
Statusbar1.Panels[1].text := ('Disconnected');

If POP.Connected then
POP.Disconnect;


if Win32Platform = VER_PLATFORM_WIN32_NT then
    Font.Name := 'MS Shell Dlg 2'
  else
    Font.Name := 'MS Shell Dlg';
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
Did you try doing it in a blank project?

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
Never mind, i think i know why

add that line to the form's onActivate event

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
Not that i think of it, the window handle to Memo is not created yet, therefor you will get a error message, so therefore the lowerst level for you would be form's onactivate event - place it there

Shane
0
 

Author Comment

by:sfern
Comment Utility
Same error :(

This is REALLY STRANGE
0
 

Author Comment

by:sfern
Comment Utility
Undeclared Identifier??????????

It's declared :(

0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
OK, paste me here the whole unit from the blank project you created with just the memo on it

Shane
0
 

Author Comment

by:sfern
Comment Utility
It does'nt know Onexception :(


Strange !!!
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 145 total points
Comment Utility
Your blank app should look like this

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  protected
    procedure DisplayExceptions(Sender: TObject; E: Exception);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DisplayExceptions(Sender: TObject; E: Exception);
begin
 Memo1.Lines.Add(E.Message)
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Application.OnException:= DisplayExceptions;
end;

end.
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
If it does and your still getting errors, then you definetly have a faulty install of delphi - is all i can say

double check your uses clause as well, make sure everything matches up

Shane
0
 

Author Comment

by:sfern
Comment Utility
Got it !!!

Spelling mistake, it's now compiling!!!

but i still get a popup message on this line:

if (ChilkatMailMan1.SendEmail(email) = 0) then //on mail error
         begin

      Memo1.Lines.Add('Error found');

should i take it off?

0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
when you compile and run it outside of delphi ide do you get it as well

Shane
0
 

Author Comment

by:sfern
Comment Utility
I'll check
0
 

Author Comment

by:sfern
Comment Utility
GREAT!!!! It's now working...wow...application completed :)

I'm giving you the rest of my points that i have left.

Thanks for all your great help :)

0
 

Author Comment

by:sfern
Comment Utility
Did you get your points?
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
yes, thanks!

Shane
0

Featured Post

IT, Stop Being Called Into Every Meeting

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!

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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