关于dll中带有数据库控件的问题!
以前看了一篇文章,说在dll中用到数据库控件,一定要有TDataModule和TSession,是这样的吗?
如果不是,那该怎么办?
以下是我想把数据库连接做到dll中,可是当调试的时候总会冒出:“Project go.exe raised exception class EOleSysError with message"尚未调用"CoInitialize。".Process stopped.Use Step or Run to continue.”
这是我的源程序
extern "C" __declspec(dllexport) _stdcall void DBConnect();
//---------------------------------------------------------------------------
__fastcall TDBC::TDBC(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TDBC::Button1Click(TObject *Sender)
{
DBConnection->ConnectionString ="Provider=SQLOLEDB.1;Password=" + pwd->Text+";Persist Security Info=True;User ID="+user->Text+";Initial Catalog="+dbname->Text+";Data Source="+addr->Text+";";
}
//---------------------------------------------------------------------------
void __fastcall TDBC::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void _stdcall DBConnect()
{
TDBC *DBC = new TDBC(NULL);
DBC->ShowModal();
delete DBC;
}