assigning an exception handler in a library

Posted on 2014-08-05
Last Modified: 2014-08-07
I have written an exception handler that needs to be used by multiple programs, so I put it in a bpl.  However, when I try to assign the exception handler in the program like this:
Application.OnException := MyLibrary.ExceptHandler;

Open in new window

I get "Incompatible types: 'method pointer and regular procedure'". I understand that method pointers and regular procedures are different, but I don't know how to declare the exception handler in the library so it's a method pointer. I tried putting it in a class in the library, but this didn't make a difference.
Thanks in advance for your help.
Question by:EricTaylor
    LVL 25

    Accepted Solution

    try define separate class:
      TAppExceptionEventHandler = class
        procedure OnAppException(Sender: TObject; E: Exception);
      AppExceptionEventHandler: TAppExceptionEventHandler;
    .... //implementation
    procedure TAppExceptionEventHandler.OnAppException(Sender: TObject; E: Exception);
    //do stuff here

    Open in new window

    ... and use it like:
    Application.OnException := AppExceptionEventHandler.OnAppException;

    Open in new window


    Author Closing Comment

    Thanks. That did it. (I tried creating the c lass previously, but forgot to create the var part so I could access it. Your example helped.)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    758 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

    11 Experts available now in Live!

    Get 1:1 Help Now