我试图抓住TADOConnection
上丢失的连接。
我已阅读this和that文章
我已经实现了TEventDispatcher
这样的课程。
#include <utilcls.h>
#include <ADOInt.hpp>
class EventHandler : public TEventDispatcher<EventHandler,&DIID_ConnectionEvents>
{
private:
bool connected;
TForm1 *theform;
_Connection* server;
protected:
HRESULT InvokeEvent(DISPID id, TVariant *params);
public:
EventHandler();
~EventHandler();
void Connect(TForm1 *form, _Connection* srv);
void Disconnect();
};
EventHandler::EventHandler()
{
connected = false;
theform = NULL;
}
EventHandler::~EventHandler()
{
if (connected)
Disconnect();
}
实施
EventHandler *handler = new EventHandler();
HRESULT EventHandler::InvokeEvent(DISPID id, TVariant *params)
{
String data = WideString(*params);
ShowMessage("InvokeEvent : "+IntToStr(id)+" "+data);
}
void EventHandler::Connect(TForm1 *form, _Connection* srv)
{
theform = form;
server = srv;
server->AddRef();
ConnectEvents(server);
}
void EventHandler::Disconnect()
{
DisconnectEvents(server);
server->Release();
}
我试图像这样使用EventHandler类。
handler->Connect(this,ADOConnection1->ConnectionObject);
当sql server manual停止时,为什么不调用InvokeEvent
类的EventHandler
方法?