3

I'm working on a component which works with a database, and the database connection is specified from the outside of this component via a TADOConnection property, visible in the Object Inspector. I assume that the outside user may intend to make use of the events of this ADO component. Yet, I also need to be able to detect when it connects or disconnects, and other various events. Can I get the events of the TADOConnection without overriding event handlers that an outside user may have assigned?

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • By _detect_ you mean _get a notification or event_ on connect/disconnect? – jachguate Nov 23 '12 at 04:31
  • Yes, as well as all the events, such as `OnCommitTransComplete` - I just don't want to interfere with users' implementation of these events. – Jerry Dodge Nov 23 '12 at 04:45
  • 1
    Interesting factoid: The ADO connection can be dropped or disconnected sometimes without the TADOConnection.Connected property going false on you, at least for remote MS SQL Server ADO connections. This happens to me when serious network faults are happening, or the SQL server is thrashing and overloaded. – Warren P Nov 23 '12 at 19:53

1 Answers1

5

There is no solution for this without heavy side effects and/or strict limitations.

You have to reroute the events, but ...

Outside users can modify events at design time (that could be handled in a way) but also at runtime and every approach will break.

As a (maybe) possible workaround (and it is a limitation) you can publish an own descent from TADOConnection and force outside users to use this, and implement multi cast events.

If you just want to get informed to Connect/Disconnect Events, you may call the protected method TCustomConnection.RegisterClient (unit Data.DB)

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73