I searched in forum, and found a workaround which is "create connection inside dll and use the AssignConnect method to share database connection"
but when the connection work under embedded mode, it shows an error
"Cannot run second Embedded server instance for single data folder. Please see details in MyDAC help or MySQL Reference manual"
Any one can help me?
Here is my code
Code: Select all
var
Child: TForm;
begin
Child := ShowNokiaForm(Application, self, MyCustomConnection,pIniFile);
Child.Show;
extern "C" TForm * __declspec(dllexport) __stdcall ShowNokiaForm(TApplication *App, TComponent *Owner, TCustomMyConnection *MyConnection1,TIniFile *pIniFile1)
{
//--- create a new MDI child window ----
Application = App; //将主程序的application付给COM工程的application对象
InitNet();
//TCustomMyConnection *MyConnection2;
TMyConnection *FMyConnection;
TMyEmbConnection *FMyEmbConnection;
if (MyConnection1->InheritsFrom(__classid(TMyConnection)))
{
FMyConnection=new TMyConnection(NULL);
FMyConnection->AssignConnect(MyConnection1);
;
MyConnection3=FMyConnection;
}
else
{
FMyEmbConnection=new TMyEmbConnection(NULL);
FMyEmbConnection->AssignConnect(MyConnection1);
MyConnection3=FMyEmbConnection;
}
TNokiaForm *Child = new TNokiaForm(Owner,MyConnection3,pIniFile1);
return Child;
}
__fastcall TNokiaForm::TNokiaForm(TComponent* Owner,TCustomMyConnection *MyConnection1,TIniFile *pIniFile1)
: TForm(Owner)
{
MyQuery1->Connection = MyConnection1;
pIniFile2 = pIniFile1;
MyConnection2 = MyConnection1;
MyQuery1->FetchAll = false;
MyQuery1->Close();
MyQuery1->SQL->Clear();
if (GroupBy == "")
MyQuery1->SQL->Add("Select "+FormulaSQLStr+FromStr+ WhereStr);
else
MyQuery1->SQL->Add("Select "+GroupBy+","+FormulaSQLStr+FromStr+ WhereStr + " Group by "+GroupBy);
//MyQuery->SQL->Add(" limit "+IntToStr(limit));
MyQuery1->Open();
}