DelphiFAQ Home Search:
General :: Programming :: Delphi :: VCL
About the Delphi VCL (Visual Component Library)


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

A global exception handler

You may want your own global exception handler to handle "common" errors such as "out of space," etc.
If you try to create a global exception handler, you will experience that surrounding the 'Application.Run' command in the .dpr with a try...except block fails.

You will redirect TApplication's "OnException" event to your main form's exception handler "MyExceptionHandler". The redirection is done in FormCreate, similar to assigning Application.OnHint:

TForm = class()..
   { public declarations }
     procedure MyExceptionHandler(Sender : TObject; E : Exception);
 { .. }
 procedure TForm1.MyExceptionHandler(
   Sender : TObject; E : Exception );
   wRetVal : Word;
   wRetVal := MessageDlg('ERROR: ' + E.message,
                mtError, mbAbortRetryIgnore, 0);
   case wRetVal of
   mrAbort:; { handle "Abort" here... }
   mrRetry:; { handle "Retry" here... }
   mrIgnore:;{ handle "Ignore" here... }
   { or call the default exception handler:
      Application.ShowException(E); }
 procedure TForm1.FormCreate(Sender: TObject);
   Application.OnException := MyExceptionHandler;
You don't like the formatting? Check out SourceCoder then!
Generated 4:01:13 on Aug 19, 2018