I'm using BCBBuilder 6 with mydac 3.5
I have a function like the one belowe.
I'm tryng to add evento OnError using
myConn->OnError = MyConnectionSIVError;
but I got this error at compile time:
[C++ Error] Unit_DM1.cpp(136): E2034 Cannot convert 'void (_fastcall TDataModule_PMV::*)(TObject *,EDAError *,bool &)' to 'void (_fastcall * (_closure )(TObject *,EDAError *,bool &))(TObject *,EDAError *,bool &)'
what I'm wrong ?
TMyConnection * __fastcall TDataModule_PMV::NewMyConnection(String hostName)
{
String strmsg;
TMyConnection * myConn = 0;
try
{
myConn = new TMyConnection( NULL );
myConn->OnError = MyConnectionSIVError;
myConn->Pooling = false;
myConn->Server = hostName;
myConn->Database = "pmv_manager";
myConn->Username = "pmv_manager";
myConn->Password = "pmv_manager";
myConn->LoginPrompt = false;
strmsg = Format( "(conn: %s.%s.%s) ",
ARRAYOFCONST(( myConn->Server,
myConn->Database,
myConn->Username )) );
myConn->Connected = true;
}
catch( Exception & ex )
{
String serr;
serr = Format( "[DataModule_PMV::NewMyConnection] ERRORE %s %s ",
ARRAYOFCONST(( ex.Message, strmsg )) );
Util::mylog( serr );
RemoveMyConnection( myConn );
myConn = 0;
}
return myConn;
}
where MyConnectionSIVError is defined inside published section as:
void __fastcall MyConnectionSIVError(TObject *Sender, EDAError *E, bool &Fail);
regards, Enzo Arlati
error when I assign OnError event to TMyConnection
But the MyLoader demo is written in delphi, which is a lot simpler to write and also in C++ I already used the assignement of event at run-time in othet situation without problem.Ikar wrote:Please look at the MyLoader demo, OnGetColumnData event. For more information see C++ Builder Help about events handling.
Just in the reported example , when I try to assign the onError event I give the error.
Please ,do someone have some working example wirtten in BCB with OnError event assignment ?
1. Define your new event handler as a form class method (in *.h file):
2. Implement this method:
3. Change standard event handler
Code: Select all
// standard handler definition
void __fastcall MyConnection1Error(TObject *Sender, EDAError *E, bool &Fail);
// replaced handler definition
void __fastcall ReplacedMyConnection1Error(TObject *Sender, EDAError *E, bool &Fail);Code: Select all
void __fastcall TForm1::ReplacedMyConnection1Error(TObject *Sender, EDAError *E, bool &Fail)
{
MessageBoxA(Form1->Handle, "Replaced error event handler", "Caption", 0);
}Code: Select all
void __fastcall TForm1::Button1Click(TObject *Sender)
{
MyConnection1->OnError = ReplacedMyConnection1Error;
}You should create a method with the definition similar to the standard (created by IDE) definition of the MyConnectionError method (just copy the standard event handler definition, paste it and change its name) and implement this method. In any place of your program replace the standard event handler with the method created by yourself. The same principle is used in the MyLoader demo.