J
jozosoft
Unregistered / Unconfirmed
GUEST, unregistred user!
主程序(是MDI主窗体):<br>...<br><br>var<br> function Load_FeeItemInfo(App: TApplication ):TForm; stdcall; external 'FeeMana.dll';<br>...<br><br>procedure TfmMain.N8Click(Sender: TObject);<br>var<br> fmbs_FeeItemInfo:TForm;<br>begin<br> // if (not Assigned(fmbs_FeeItemInfo)) or (fmbs_FeeItemInfo = Nil) then<br> begin<br> fmbs_FeeItemInfo:= Load_FeeItemInfo( Application);<br> end;<br> // fmbs_FeeItemInfo.Show; <br>end;<br><br><br>--------------------------------<br>Dll窗体(要作成MDI子窗体)<br>library FeeMana;<br><br>{ Important note about DLL memory management: ShareMem must be the<br> first unit in your library's USES clause AND your project's (select<br> Project-View Source) USES clause if your DLL exports any procedures or<br> functions that pass strings as parameters or function results. This<br> applies to all strings passed to and from your DLL--even those that<br> are nested in records and classes. ShareMem is the interface unit to<br> the BORLNDMM.DLL shared memory manager, which must be deployed along<br> with your DLL. To avoid using BORLNDMM.DLL, pass string information<br> using PChar or ShortString parameters. }<br><br>uses<br> SysUtils,<br> Classes,<br> Forms,<br> Windows,<br> Messages,<br> Dialogs,<br> ActiveX,<br> DB,<br> ADODB,<br> <br> FeeItemInfo in 'FeeItemInfo.pas' {fmbs_FeeItemInfo};<br><br>var<br> DLLApp: TApplication;<br> DLLScr: TScreen;<br><br> pubAdoConn:TAdoConnection;<br>{$R *.res}<br><br><br>procedure ExitDLL(Reason: Integer); register;<br>begin<br> showmessage('Dll退出!');<br> if(Reason = DLL_PROCESS_ATTACH) then<br> begin<br> CoInitialize(nil) ;<br> end ;<br><br> if Reason = DLL_PROCESS_DETACH then<br> begin<br> Screen:= DLLScr;<br> Application := DLLApp;<br> <br> end;<br>end;<br> <br>function Load_FeeItemInfo(App: TApplication ):TForm; stdcall;<br>var<br> i:integer;<br>begin<br> Application := App; //******请注意此行!!!!<br> // CoInitialize(nil) ;<br><br> showmessage('staart1');<br> if (not Assigned(fmbs_FeeItemInfo)) or (fmbs_FeeItemInfo = Nil) then<br> begin<br> <br> fmbs_FeeItemInfo:=Tfmbs_FeeItemInfo.Create(app );<br> fmbs_FeeItemInfo.FormStyle:=fsMDIChild;<br> fmbs_FeeItemInfo.Visible :=True;<br> <br> <br> end;<br> Result:=fmbs_FeeItemInfo;<br>end;<br> <br><br><br>exports<br> Load_FeeItemInfo;<br>begin<br> <br><br> DLLApp := Application;<br> DLLScr := Screen;<br> DLLProc := @ExitDLL; <br>end.<br><br>-----------<br>Dll子窗体的 OnClose中写有:<br>procedure Tfmbs_FeeItemInfo.FormClose(Sender: TObject;<br> var Action: TCloseAction);<br>begin<br> action:=cafree;<br> fmbs_FeeItemInfo:=Nil;<br>end;<br><br><br><br>************************************<br>错误:<br>1.如果去掉以下这行, 没有显示MDI子窗体,而是出错(退出主程序不会报内存出错):<br> <br> 出错信息: Exception EInvalidOperation in module FeeMana.dll at 000549DF.<br><br> Application := App; //******请注意此行!!!!<br><br>2.如果加上Application := App;这一行, 能显示子窗体,但退出主程序后报内容出错:<br> Runtime error 216 at 004C36E6. <br><br>3. ExitDLL 这个函数我发现系统在退出时好像没有执行。