调用DLL中的MDICHILD窗体后,过一段时间,窗体自动关闭,主程序无响应。主程序和DLL都没带包编译。

解决方案 »

  1.   

    var
    FormHandle:hwnd;
    dllapp:tapplication;
    procedure LoadsysreportDLL(PApplication:TApplication;PForm: TForm;FormName:shortString;MainHandle:integer;datamodule:Tfrm_dm;pdepartment:shortstring); export; stdcall;
    begin
       Application:=PApplication;
      // Screen := Scr;
       FormHandle:=MainHandle;
       frm_dm:=datamodule;
       depment:=pdepartment;
       if FormName='frm_count' then
       begin
         if not Assigned(frm_count) then
           frm_count:= Tfrm_count.Create(PForm);
       end;   if FormName='frm_order' then
       begin
         if not Assigned(frm_order) then
           frm_order:=Tfrm_order.Create(PForm);
       end;   if FormName='frm_plantp' then
       begin
         if not Assigned(frm_plantp) then
           frm_plantp:=Tfrm_plantp.Create(PForm);
       end;   if FormName='frm_time' then
       begin
         if not Assigned(frm_time) then
           frm_time:= Tfrm_time.Create(PForm);
       end;
    end;
    procedure  DLLUnloadProc(Reason:Integer);register;
    begin
          if  (Reason=DLL_PROCESS_DETACH) or (Reason=DLL_THREAD_DETACH)   then
          begin
          if assigned(frm_count) then
          frm_count.Free;
          if assigned(frm_order) then
          frm_order.Free;
          if assigned(frm_plantp) then
          frm_plantp.Free;
          if assigned(frm_time) then
          frm_time.Free;
          Application:=DllApp;
          CoUnInitialize;
          end;
    end;
    exports LoadsysreportDLL;
    begin
     DllApp:= Application;
     CoInitialize(nil);
     DLLProc := @DLLUnloadProc;
    end.
      

  2.   

    DLL 中DATAMODULE是直接引用主程序中的DATAMODULE,传递frm_dm对象。