Link to home
Start Free TrialLog in
Avatar of sfern
sfern

asked on

Stop Program Popup Errors and exceptions

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.
Avatar of shaneholmes
shaneholmes

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;


or get madExcept at www.madshi.net

Shane
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....
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
Avatar of sfern

ASKER

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
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.
Avatar of sfern

ASKER

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




hmmm, what version of delphi are you using....

SHane

Try creating a blank application and try pluggin in my code and see what you get

SHane
Avatar of sfern

ASKER

OK, thanks, i have to try it a bit later though, from home.

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

Avatar of sfern

ASKER

Cannot get it to work, same errors :(

Any ideas?

Thanks
Again, what version of delphi????

Shane
and did you create a blank application?

Shane
Avatar of sfern

ASKER

yes :(

I'm using delphi 6 Ent
k, open up help, search for TApplication, and look at its events

You should see OnException

Shane
Let me know if you find it?

Shane
Avatar of sfern

ASKER

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 :(
hmmm - in your application , or in the new blank application.

Cause i dont get any errors in my Form Create

Shane
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


Avatar of sfern

ASKER

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;
Did you try doing it in a blank project?

Shane
Never mind, i think i know why

add that line to the form's onActivate event

Shane
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
Avatar of sfern

ASKER

Same error :(

This is REALLY STRANGE
Avatar of sfern

ASKER

Undeclared Identifier??????????

It's declared :(

OK, paste me here the whole unit from the blank project you created with just the memo on it

Shane
Avatar of sfern

ASKER

It does'nt know Onexception :(


Strange !!!
ASKER CERTIFIED SOLUTION
Avatar of shaneholmes
shaneholmes

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of sfern

ASKER

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?

when you compile and run it outside of delphi ide do you get it as well

Shane
Avatar of sfern

ASKER

I'll check
Avatar of sfern

ASKER

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 :)

Avatar of sfern

ASKER

Did you get your points?
yes, thanks!

Shane