Solved

Resume error

Posted on 2003-11-26
5
302 Views
Last Modified: 2012-05-04
How can we avoid to appear the message dialog box error? Is there any way with Try except on...? The object is to resume this box without the user to notice it. Anyway can we put this error in a Variable?
Thanks,
Luis
0
Comment
Question by:lfgmartins
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:mocarts
ID: 9824078
hi, Luis :)
You can use TApplicationEvents component (located on Additional component palette page) and define OnException event to provide custom behaviour when unhandled exception occurs.
See Delphi help for detailed description and example.

wbr, mo.
0
 
LVL 9

Assisted Solution

by:mocarts
mocarts earned 100 total points
ID: 9824108
addition: you can define your OnException event handler even without TApplicationEvents component by directly assigning your custom event handler to Application global variables OnException property (Application variable for standard applications resides in Forms.pas unit):

uses ...Forms;
type
  TForm1 = class(TForm)
  ..
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    procedure MyExceptionHandler(Sender: TObject; E: Exception);
  end;

implementation

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

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Application.OnException := MyExceptionHandler
end;

procedure TForm1.MyExceptionHandler(Sender: TObject; E: Exception);
begin
  LogToFile(DateTimeToStr(Now) +': '+ E.Message);
end;
0
 
LVL 5

Assisted Solution

by:Darth_helge
Darth_helge earned 200 total points
ID: 9824497
maybe I'm totally wrong here, but.. u want the program to ignore the error?
use an empty try..except block.

procedure TForm1.Button1Click(Sender: TObject);
var
Q: TADOQuery;
begin
 try
 showmessage(Q.Fields[0].AsString);
 except
 end;
 showmessage('program resumed');
end;

normally the showmessage(Q.fields[0].asString) would have produced a "list index out of bounds error", but with inside an empty try..except it just resumes the program and writes the showmessagebox beneath..
0
 
LVL 17

Accepted Solution

by:
geobul earned 200 total points
ID: 9826076
Just my 2 cents:
If you are running your app from inside the Delphi IDE there will be an error box (or uncheck 'Stop on Delphi Exceptions' checkbox in Tools-Debugger Options-Language Exceptions tab). But if you're running your app as usual exe and have used try
  ..
except
end;

then there won't be an error.

Regards, Geo
0
 
LVL 17

Assisted Solution

by:geobul
geobul earned 200 total points
ID: 9826144
About saving errors: another way

procedure TForm1.Button1Click(Sender: TObject);
var
  sError: string;
  i: integer;
begin
  sError := '';
  try
    i := StrToInt('asdf');
  except
    on E: Exception do sError := E.Message;
  end;
  if sError <> '' then begin
    ShowMessage(sError);
    sError := '';
  end;
  ....
end;

Regards, Geo
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

16 Experts available now in Live!

Get 1:1 Help Now