調用含有窗體的DLL,關閉主窗體時報錯 ( 积分: 100 )

  • 主题发起人 主题发起人 skysword9
  • 开始时间 开始时间
S

skysword9

Unregistered / Unconfirmed
GUEST, unregistred user!
寫了一個DLL,內含有窗口,另外有DATABASE,QUERY等控件,
在主窗口中調用該DLL,打開窗口,運行正常,關閉該窗口,正常,
但是,關閉主窗口時報錯:Invalid pointer;
不論動態調用還是靜態調用均如此,dll中相應unit均使用了sharemem,
請大俠指點
 
寫了一個DLL,內含有窗口,另外有DATABASE,QUERY等控件,
在主窗口中調用該DLL,打開窗口,運行正常,關閉該窗口,正常,
但是,關閉主窗口時報錯:Invalid pointer;
不論動態調用還是靜態調用均如此,dll中相應unit均使用了sharemem,
請大俠指點
 
哪位大俠幫忙指點指點
 
我也碰到过这个问题,期待高手解答!!!
 
dll中用ADO要CoInitialize(nil); CoUninitialize
 
library DllTestFI;

{ 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
ShareMem,
SysUtils,
Forms,
ADODB,
Windows,
Dialogs,
Messages,
Classes,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

var
//主框架程序变量申明
DLLApp: TApplication;
DLLScr: TScreen;


function CreateDLLForm(App: TApplication; Scr: TScreen; User: string; ADOC: TADOConnection; FormSeq: integer):TForm;
begin
case FormSeq of
1 :
begin
Application := App;
Screen := Scr;
Application.CreateForm(TForm1, Form1);
Form1.ADOQuery1.Connection := ADOC;
result := Form1;
end;
2 :
begin
Application := App;
Screen := Scr;
Application.CreateForm(TForm2 , Form2);
Form2.ADOQuery1.Connection := ADOC;
result := Form2;
end;
end;
end;

procedure ExitDLL(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScr;
end;
end;


exports
CreateDLLForm;

begin
DLLApp := Application;
DLLScr := Screen;
DLLProc := @ExitDLL;
end.
 
DLL.gif
 
感謝大俠,但是我的數據庫連接使用的是BDE,沒有使用ADO阿,
請教可能是甚麼原因?如何解決
 
dywapple,你好,
我將你的代碼移到我的程序中,使用BDE,還是報:invalid pointer operation
是否有其他原因呢?
 
你的database不要放在DLL中,因为在BDE中,只要主程序连接成功后,databasename就可以用字符串的形式继续使用的,你试着把DLL中DATABASE 删除
 
你的主程序中有沒有sharemem
 
我也执行了同样的代码,没有发生异常。
 
带包编译
 
多人接受答案了。
 
后退
顶部