DLL代码如下:library SYSDLL;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes,
Forms,
Dictionary in 'Dictionary.pas' {frmDictionary},
Functions in '..\..\Include\Functions.pas',
waitquery in '..\..\Include\waitquery.pas' {frmWaitQuery},
ErrorInfo in '..\..\Include\ErrorInfo.pas' {frmErrorInfo},
BaseFunctions in '..\..\Include\BaseFunctions.pas',
ADOConnection in '..\..\Include\ADOConnection.pas';{$R *.res}
function CreateDllFrm(sFrmName: String): Boolean; StdCall;
begin
Result := True;
if sFrmName = '' then
ErrorFrm('窗体参数不能为空...', 1);
end; try
case sFrmName of
'frmDictionary':
begin
Application.CreateForm(TfrmDictionary, frmDictionary);
frmDictionary.ShowModal;
frmDictionary.Free;
end;
end;
except
end;
end;exports
CreateDllFrm;
end.DLL中的form要如何才能使用调用它的EXE里已经创建的ADO连接?
请赐教啊。
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Classes,
Forms,
Dictionary in 'Dictionary.pas' {frmDictionary},
Functions in '..\..\Include\Functions.pas',
waitquery in '..\..\Include\waitquery.pas' {frmWaitQuery},
ErrorInfo in '..\..\Include\ErrorInfo.pas' {frmErrorInfo},
BaseFunctions in '..\..\Include\BaseFunctions.pas',
ADOConnection in '..\..\Include\ADOConnection.pas';{$R *.res}
function CreateDllFrm(sFrmName: String): Boolean; StdCall;
begin
Result := True;
if sFrmName = '' then
ErrorFrm('窗体参数不能为空...', 1);
end; try
case sFrmName of
'frmDictionary':
begin
Application.CreateForm(TfrmDictionary, frmDictionary);
frmDictionary.ShowModal;
frmDictionary.Free;
end;
end;
except
end;
end;exports
CreateDllFrm;
end.DLL中的form要如何才能使用调用它的EXE里已经创建的ADO连接?
请赐教啊。
解决方案 »
- (菜鸟级问题)怎么实现用Label控件拖动窗口?拖动完了不能激发OnClick事件
- 水平不上不下,该何去何从?(求教高手们如何进阶)
- quickreport问题 急!!!
- 在登陆时怎样验证特殊字符?
- 在数据库保存图片,什么方式最好
- 也许是很简单的问题,但是我被搞得好郁闷
- 求:有哪位大侠有考试系统没有?我想开发一套考试系统,但还有些东西不知道怎么做。
- 如何设置数字字段在dbgrid显示的时候如果是0则不显示??
- 李维的<delphi5.x--多层系统>有没有电子版?或下载地址?
- 关于flash的,又不是关于flash的!
- 能否在Serversocket接收数据以前,就对他进行检测,有数据就接收,没有就等待
- 50分求《Inside VCL(深入核心——VCL架构剖析)》电子版
function connect(DLLconnect:TADOConnection):true;stdcall;
begin
try
begin
DLLquery.Connection:=DLLconnect;
result:=true;
end;
except
begin
result:=false;
end;
end;
EXE和DLL是两个项目文件。
EXE在创建的时候会联立一个ADOCon的数据库长连接。
我想在DLL中也使用它,而不想再建连接。创建代码如下:
try
Adocon := TAdoConnection.Create(nil);
Adocon.LoginPrompt := False;
bDBConnected := False;
if not AdoConnSqlDb(AdoCon,sPassword,server,'master',sUser) then
begin
ErrorFrm('连接数据库失败,请重试或重新设置数据连接参数和数据库用户密码!', 1);
AdoCon.Free;
bDBConnected := False;
Application.CreateForm(TfrmParamForm, frmParamForm);
Exit;
end;
except
ShowMessage('连接数据库失败,请重试或重新设置数据连接参数!');
AdoCon.Free;
Application.Terminate;
end;
procedure DoTest(H: THandle; { 传递句柄 }
AConn: TADOConnection; { 传递数据库连接 }
S: string; { 传递文本信息 }
N: Integer); { 传递数值信息 }
cdecl; { 指定调用协议 }
http://search.csdn.net/Expert/topic/1645/1645329.xml?temp=.5659906
记得结贴给分噢:)
只是示例中的情况和我的刚好相反。示例中是EXE通过DLL创建ADO连接,我这里的问题是DLL中的模块需要引用EXE中的ADO连接,还情各位DX明示下。
try
Adocon := TAdoConnection.Create(nil);
Adocon.LoginPrompt := False;
bDBConnected := False;
if not AdoConnSqlDb(AdoCon,sPassword,server,'master',sUser) then
begin
ErrorFrm('连接数据库失败,请重试或重新设置数据连接参数和数据库用户密码!', 1);
AdoCon.Free;
bDBConnected := False;
Application.CreateForm(TfrmParamForm, frmParamForm);
Exit;
end;
except
ShowMessage('连接数据库失败,请重试或重新设置数据连接参数!');
AdoCon.Free;
Application.Terminate;
end;DLL中的一个form需要的ADO连接如下,
try
begin
【 Connection := Adocon; 】
ProcedureName := 'sql..sp_sys_dict_set';
Parameters.CreateParameter('@staff_id', ftInteger, pdInput, 4, CommonInfo.StaffID);
Parameters.CreateParameter('@st_station', ftstring, pdInput, 12, CommonInfo.MAC);
Parameters.CreateParameter('@action', ftInteger, pdInput, 4, iAction);
Parameters.CreateParameter('@dict_prompt', ftstring, pdInput, 255, Trim(sedtdictprompt.Text));
Parameters.CreateParameter('@error_info', ftString, pdOutput, 255, '');
ExecProc;我该如何是好,这个form原本在exe里的,现在准备要放到DLL里公用。
如果要用adoconnection,動態創建一個不就行了麼或者直接寫:
ADOStoredProc1.ConnectionString:=FConStr;
ADOQuery1.ConnectionString:=FConStr;
ADODataSet1.ConnectionString:=FConStr;你怎樣用都行. 想問題要靈活些.
而且每次重连数据库有时会很慢,所以这种做法不太考虑,
如果动态传建的话我们的数据库连接配置都是在注册表里的,也不用当成参数传来传去。