月
月满C楼
Unregistered / Unconfirmed
GUEST, unregistred user!
//dll中返回给主程序的MDI子窗体在关闭时出错,就是访问内存地址出错的那一种错误library Stick;uses //没有使用string数据类型,所以没有引用SharedMem单元(主程序和所有的dll都没有引用该单元) SysUtils, windows, Messages, Classes, ADODB, Forms, dialogs, recv in 'recv.pas' {frmRecv}, define in 'define.pas', unite in 'unite.pas' {frmUnite};const ArrFormClass : array[0..1] of TFormClass=(TfrmRecv,TfrmUnite); ArrClassName : array[0..1] of String=('frmRecv','frmUnite');var DLLApp:TApplication; DLLScr:TScreen;procedure init(app:TApplication;userNamechar;formNamechar;menuIdchar;conn:TADOConnection);stdcall;var i:integer; frm:TForm;begin application:=app; for i:=low(ArrClassName) to high(ArrClassName) do begin if formName=ArrClassName then begin frm:=ArrFormClass.Create(app); frm.Hint:=menuId; frm.Parent:=app.MainForm; frm.Show; exit; end;//end if end;//end for iend;procedure ExitDLL(Reason:Integer);begin if (Reason=DLL_PROCESS_DETACH) then begin Application:=DLLApp; Screen:=DLLScr; SendMessage(Application.Handle,WM_CLOSE,0,0); FreeLibrary(Application.Handle); end;end;exports init;{$R *.res}begin DLLApp:=Application; DLLScr:=Screen; DLLProc:=@ExitDLL;end.------------------------------以下是dll中1个子窗体的代码,很简单就是关闭时使用了caAction:=caFree;unit recv;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, Buttons, ExtCtrls;type TfrmRecv = class(TForm) Panel1: TPanel; Panel2: TPanel; BitBtn1: TBitBtn; DBGrid1: TDBGrid; procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end;var frmRecv: TfrmRecv;implementation{$R *.dfm}procedure TfrmRecv.FormClose(Sender: TObject; var Action: TCloseAction);begin Action:= caFree;end;initialization RegisterClass(TfrmRecv);finalization UnRegisterClass(TfrmRecv);end.