Solved

Stop Program Popup Errors and exceptions

Posted on 2004-04-27
36
229 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
ID: 10931847
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
ID: 10931854


or get madExcept at www.madshi.net

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10931874
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
LVL 12

Expert Comment

by:esoftbg
ID: 10931881
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
ID: 10931966
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
ID: 10932112
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
ID: 10932167
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
ID: 10932309
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
ID: 10932342
hmmm, what version of delphi are you using....

SHane

0
 
LVL 11

Expert Comment

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

SHane
0
 

Author Comment

by:sfern
ID: 10932444
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
ID: 10933644
Cannot get it to work, same errors :(

Any ideas?

Thanks
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10933649
Again, what version of delphi????

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10933652
and did you create a blank application?

Shane
0
 

Author Comment

by:sfern
ID: 10933725
yes :(

I'm using delphi 6 Ent
0
 
LVL 11

Expert Comment

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

You should see OnException

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10933766
Let me know if you find it?

Shane
0
 

Author Comment

by:sfern
ID: 10933836
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
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10933844
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
ID: 10933867
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
ID: 10933877
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
ID: 10933881
Did you try doing it in a blank project?

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10933884
Never mind, i think i know why

add that line to the form's onActivate event

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10933889
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
ID: 10933903
Same error :(

This is REALLY STRANGE
0
 

Author Comment

by:sfern
ID: 10933909
Undeclared Identifier??????????

It's declared :(

0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10933911
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
ID: 10933915
It does'nt know Onexception :(


Strange !!!
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 145 total points
ID: 10933926
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
ID: 10933932
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
ID: 10933954
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
ID: 10933964
when you compile and run it outside of delphi ide do you get it as well

Shane
0
 

Author Comment

by:sfern
ID: 10933972
I'll check
0
 

Author Comment

by:sfern
ID: 10933980
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
ID: 10934006
Did you get your points?
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10934054
yes, thanks!

Shane
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 115
tidtcpserver connection lost handle 2 102
RESTRequest Parameter 4 42
Tvertscrollbox like a whatsapp layout delete messages 1 24
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

861 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