Page 1 of 1

error when I assign OnError event to TMyConnection

Posted: Mon 06 Feb 2006 08:51
by earlati
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

Posted: Tue 07 Feb 2006 07:19
by Ikar
Please look at the MyLoader demo, OnGetColumnData event. For more information see C++ Builder Help about events handling.

Posted: Tue 07 Feb 2006 07:53
by earlati
Ikar wrote:Please look at the MyLoader demo, OnGetColumnData event. For more information see C++ Builder Help about events handling.
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.
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 ?

Posted: Tue 07 Feb 2006 10:11
by Ikar
1. Define your new event handler as a form class method (in *.h file):

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);
2. Implement this method:

Code: Select all

  void __fastcall TForm1::ReplacedMyConnection1Error(TObject *Sender, EDAError *E, bool &Fail)
  {
        MessageBoxA(Form1->Handle, "Replaced error event handler", "Caption", 0);
  }
3. Change standard event handler

Code: Select all

  void __fastcall TForm1::Button1Click(TObject *Sender)
  {
        MyConnection1->OnError = ReplacedMyConnection1Error;
  }

Posted: Fri 10 Nov 2006 22:34
by khh
Can you rewrite last post in Delphi!

Thank you

Posted: Tue 14 Nov 2006 14:56
by Antaeus
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.