error when I assign OnError event to TMyConnection

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
earlati
Posts: 18
Joined: Thu 18 Nov 2004 07:37
Location: Bergamo / Italy

error when I assign OnError event to TMyConnection

Post by earlati » Mon 06 Feb 2006 08:51

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

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Tue 07 Feb 2006 07:19

Please look at the MyLoader demo, OnGetColumnData event. For more information see C++ Builder Help about events handling.

earlati
Posts: 18
Joined: Thu 18 Nov 2004 07:37
Location: Bergamo / Italy

Post by earlati » Tue 07 Feb 2006 07:53

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 ?

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Tue 07 Feb 2006 10:11

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;
  }

khh
Posts: 37
Joined: Wed 17 Nov 2004 17:10

Post by khh » Fri 10 Nov 2006 22:34

Can you rewrite last post in Delphi!

Thank you

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 14 Nov 2006 14:56

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.

Post Reply