关于dll连接oracle(50分)

  • 主题发起人 主题发起人 huddle
  • 开始时间 开始时间
H

huddle

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

Similar threads

回复
0
查看
1K
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部