如题:
dll里有form1窗体和datamodule1数据模块,datamodule1里有ado数据集组件,form1窗体里有ado查询,问题是:当调用dll里的form1时,查询功能不能用了,就是数据模块里的ado出错,请问怎样解决呀???????
dll里有form1窗体和datamodule1数据模块,datamodule1里有ado数据集组件,form1窗体里有ado查询,问题是:当调用dll里的form1时,查询功能不能用了,就是数据模块里的ado出错,请问怎样解决呀???????
library P_tnbjk_dll;uses
windows,
SysUtils,
Classes,
Forms,
ComObj, Unit1 in 'Unit1.pas' {Form1},
U_DM in 'U_DM.pas' {DM: TDataModule},
U_bjzd in 'U_bjzd.pas' {Frm_bjzd};{$R *.res} function ShowForm(aHandle:THandle;acaption:pchar):Boolean;stdcall;
var
form1:tform1;
begin
Application.Handle:=aHandle;
form1:=tform1.Create(Application);
try
form1.ShowModal;
finally
form1.Free;
end;
Result:=true;
end;exports showform;begin
end.
procedure TForm1.FormCreate(Sender: TObject);
begin
dm:=tdm.create(self);
end;
运行时会有:---------------------------
Project1
---------------------------
尚未调用 CoInitialize。.
---------------------------
确定
---------------------------
原因是没有Application.initialize,即没有对COM对象初始化。如果在Delphi的Dll里面使用了ADO组件,那么需要在使用之前调用ActiveX的CoInitialize方法。
例如:CoInitialize();
query := TADOQuery.Create(nil);
最好把代码贴出来。
windows,
SysUtils,
Classes,
Forms,
ComObj, Unit1 in 'Unit1.pas' {Form1},
U_DM in 'U_DM.pas' {DM: TDataModule},
U_bjzd in 'U_bjzd.pas' {Frm_bjzd};{$R *.res}
procedure ExitDLL(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
//写释放数据源的代码
//
CoUnInitialize;
Application := DLLApp;
Screen := DLLScr;
end;
end;
begin
CoInitialize(nil);
SaveExit:=ExitProc;
DLLApp := Application;
DLLScr := Screen;
ExitProc:=@ExitDLL;
end.