//这是Dll代码:<br>unit LinkADO;<br><br>interface<br><br>uses<br> SysUtils, ADODB;<br><br> function ConnectOracle(aSID, aUser, aPassword: string; aADO: TADOConnection; out aErrMsg: string): boolean;<br><br>implementation<br><br>{<br> 功能:连接指Oracle数据库。在 TADOConnection 中返回连接.<br> 入口参数:aSID, aUser, aPassword分别为数据库SID,用户名、密码,aADO为需要连接的TADOConnection控件。<br> 返回值:成功返回true,失败返回false,并且在 aErrMsg中返回错误信息。<br>}<br>function ConnectOracle(aSID, aUser, aPassword: string; aADO: TADOConnection; out aErrMsg: string): boolean;<br>begin<br> Result:= false;<br> aErrMsg:= '';<br> with aADO do<br> begin<br> Close;<br> ConnectionString:= 'Provider=MSDAORA.1;Password=' + aPassword +<br> ';User ID=' + aUser +<br> ';Data Source=' + aSID +<br> ';Persist Security Info=False';<br> try<br> Open;<br> Result:= Connected = true;<br> except on E: Exception do<br> aErrMsg:= E.Message;<br> end;<br> end;<br>end;<br>//需要在dll工程文件中导出,写:<br>library ADOLnk;<br>。。。<br>Exports<br> ConnectOracle; //导出Dll<br>begin<br><br>//如何调用:<br>...<br>type<br> //过程类型,(函数指针)<br> TCallOracle = function (aSID, aUser, aPassword: string;<br> aADO: TADOConnection; out aErrMsg: string):boolean; //stdcall;<br><br><br>var<br> Form1: TForm1;<br> DllHandle: THandle = 0;<br> fp: TCallOracle;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> sErrStr: string;<br>begin<br> DllHandle:= LoadLibrary('ADOLnk.dll');<br> if DllHandle <> 0 then<br> begin<br> fp:= GetProcAddress(DllHandle, 'ConnectOracle');<br> if fp('OracleSID', 'Admin', 'Password', ADOConnection1, sErrStr) then<br> begin<br> ADOQuery1.Open;<br> Application.MessageBox(PChar('Oracle连接成功!'),'提示',MB_OK + MB_ICONINFORMATION);<br> end else<br> begin<br> Application.MessageBox(PChar('Oracle连接失败!,错误信息:' +<br> sErrStr ),'错误',MB_OK + MB_ICONERROR);<br> end;<br> FreeLibrary(DllHandle);<br> end;<br>end;<br><br>end.