Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8110207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:40:06+00:00 2026-06-06T01:40:06+00:00

I am programmatically creating a database connection object inside a simple procedure (not a

  • 0

I am programmatically creating a database connection object inside a simple procedure (not a method in a class).

mydb:= TUniConnection.Create(nil);
mydb.Database:= knowledge_db_name;
mydb.LoginPrompt:= False;
mydb.Username:= aaa;
mydb.Password:= bbb;

now I need to handle errors and disconnections with other procedures. When I try to do:

mydb.OnError:= OnConnectionError;
mydb.OnConnectionLost:= OnConnectionLost;

The compiler tells me

[DCC Error] test.pas(373): E2009 Incompatible types: 'method pointer and regular procedure'

How can I work around this?
Here are the definitions of the event procedures:

procedure OnConnectionError(Sender: TObject; E: EDAError; var Fail: Boolean);
procedure OnConnectionLost(Sender: TObject; Component: TComponent; ConnLostCause: TConnLostCause; var RetryMode: TRetryMode);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:40:08+00:00Added an answer on June 6, 2026 at 1:40 am

    If you don’t have a suitable class to put the event handlers in you can define a dummy class and make the event handlers class procedures. Then you don’t have to create an instance of the class but can assign mydb.OnError:= TMyDummyEventHandlerClass.OnConnectionError;.

    Here is an example – I use different events because I don’t have TUniConnection but want to be sure everything compiles. 🙂

    type
      // Dummy class to hold event handlers:
      TXMLEventHandlers = class
        // Event handlers:
        class procedure OnBeforeOpen(Sender: TObject);
        class procedure OnAfterOpen(Sender: TObject);
      end;
    
    class procedure TXMLEventHandlers.OnBeforeOpen(Sender: TObject);
    begin
      MessageBox(0, PChar(ClassName + '.OnBeforeOpen'), nil, 0)
    end;
    
    class procedure TXMLEventHandlers.OnAfterOpen(Sender: TObject);
    begin
      MessageBox(0, PChar(ClassName + '.OnAfterOpen'), nil, 0)
    end;
    
    procedure Test;
    var
      xml: TXMLDocument;
    begin
      xml := TXMLDocument.Create(nil);
      try
        // Note: No instance of `TXMLEventHandlers` must be created:
        xml.AfterOpen := TXMLEventHandlers.OnAfterOpen;
        xml.BeforeOpen := TXMLEventHandlers.OnBeforeOpen;
    
        xml.Active := True; // Calls the two event handlers
      finally
        xml.Free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a SQL Server database programmatically during a conversion. If the conversion
I am programmatically creating a DataGridView object and then binding it to a DataTable
I'm creating a SQL CE database file programmatically and want to make sure I'm
I was creating connection string for sql express database dynamically.I wanted to know how
I'm programmatically creating a tab bar based app. In the application:didFinishLaunchingWithOptions (app delegate) method
I use the Ant API for creating tasks programmatically, but I have not yet
I am programmatically creating a view in the loadView method of my view controller.
I am programmatically creating a tableview in objective c. How can I make the
I'm programmatically creating an edmx file as part of our code generation process and
I'm programmatically creating a folder using C# and need to set the default view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.