CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
英特尔®游戏设计大赛100美元现金周周送 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

关于连续两次打开dll中子窗口的mainmenu菜单后报错的问题

楼主luck2050(fjx)2003-09-01 22:56:49 在 Delphi / VCL组件开发及应用 提问

我在主程序exe中打开dll中子窗口的mainmenu菜单后关闭这个子窗口,然后重复这个操作就报错,也就是不能连续调用两次,但只要不用子窗口的mainmenu或者主程序exe中调用窗不含有mainmenu就不会报错,那位大哥帮我瞧一下呀  
   
  //dll的调用程序如下  
  unit   MainUnit;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   StdCtrls,   ExtCtrls,   Menus,   publicUnit,   Grids,   DB,   ADODB,  
      DBClient,   MConnect,   SConnect;  
   
  type  
      TfrmMain   =   class(TForm)  
          MainMenu1:   TMainMenu;  
          N1:   TMenuItem;  
          Panel1:   TPanel;  
          Button1:   TButton;  
          Button2:   TButton;  
          procedure   N1Click(Sender:   TObject);  
          procedure   Button1Click(Sender:   TObject);  
          procedure   Button2Click(Sender:   TObject);  
        private  
            procedure   WMGetDlgCode(var   msgIn:   TWMGetDlgCode);   message   WM_GETDLGCODE;  
      public  
          {   Public   declarations   }  
    end;  
  type  
  tnet=array[0..3]   of   pchar;  
  var  
      frmMain:   TfrmMain;  
  function   ShowDllForm(App:   TApplication;   ACaption:   string;   sc:   TScreen):   Longint;  
  stdcall;   external   'prjDll.dll';  
  //function   openform(App:TApplication;sc:tscreen;netpara:tnet):Longint;  
  //stdcall;External'..\rzbinfo\reportbuild\reportbuild.dll';  
  //function   openForm(App:   TApplication;sc:   TScreen;netpara:tnet):   Longint;  
  //stdcall;external'..\rzbinfo\reportbuild\reportbuild.dll';  
  implementation  
   
  {$R   *.dfm}  
   
   
   
  procedure   TfrmMain.N1Click(Sender:   TObject);  
  begin  
      ShowDllForm(Application,   '子窗体',   Screen);  
  end;  
   
   
   
   
  procedure   TfrmMain.WMGetDlgCode(var   msgIn:   TWMGetDlgCode);  
  begin  
      inherited;  
      msgIn.Result   :=   msgIn.Result   or   DLGC_WANTTAB;  
  end;  
   
  procedure   TfrmMain.Button1Click(Sender:   TObject);  
  //var  
  //netp:tnet;  
  begin  
  {netp[0]:=pchar(socketconnection1.Address);  
  netp[1]:=pchar(inttostr(socketconnection1.Port));  
  netp[2]:=pchar(socketconnection1.ServerName);  
  netp[3]:=pchar(socketconnection1.ServerGUID);  
  openForm(Application,Screen,netp);}  
  end;  
   
  procedure   TfrmMain.Button2Click(Sender:   TObject);  
  begin  
      ShowDllForm(Application,   '子窗体',   Screen);  
  end;  
   
  end.  
   
  //dll如下  
  library   prjDLL;  
   
   
  uses  
      SysUtils,  
      Classes,  
      Windows,  
      Forms,  
      childUnit   in   'childUnit.pas'   {frmChild},  
      Unit1   in   'Unit1.pas'   {Form1};  
   
  {$R   *.res}  
   
  var  
      DLLApp:   TApplication;  
      DLLScreen:TScreen;  
   
  function   ShowDllForm(App:TApplication;   ACaption:String;   sc:TScreen):Longint;stdcall;  
  begin  
      Application   :=   App;  
      Screen:=sc;  
   
      if   not   Assigned(frmChild)   then  
          frmChild:=TfrmChild.Create(Application);  
      Result:=Longint(frmChild);  
      frmChild.Caption   :=   ACaption;  
      frmChild.Show;  
  end;  
   
  procedure   DLLUnloadProc(Reason   :   Integer);  
  begin  
      if   Reason   =   DLL_PROCESS_DETACH   then   begin  
          Application   :=   DLLApp;//恢复  
          Screen:=DLLScreen;  
      end;  
  end;  
   
   
  exports  
      ShowDllForm;  
   
  begin  
      DLLApp   :=   Application;   //保存   DLL   中初始的   Application   对象  
      DLLScreen:=Screen;  
      DLLProc   :=   @DLLUnloadProc;           //保证   DLL   卸载时恢复原来的   Application  
  end.  
   
   
   
   
  //frmchild如下  
   
  unit   childUnit;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   publicUnit,   Grids,   DB,   ADODB,   DBGrids,   Menus,   StdCtrls;  
   
  type  
      TfrmChild   =   class(TForm)  
          ComboBox1:   TComboBox;  
          MainMenu1:   TMainMenu;  
          xxx1:   TMenuItem;  
          xxxx1:   TMenuItem;  
          xxxx2:   TMenuItem;  
          procedure   FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
          procedure   FormKeyPress(Sender:   TObject;   var   Key:   Char);  
          procedure   FormCreate(Sender:   TObject);  
          procedure   xxxx2Click(Sender:   TObject);  
      private  
          procedure   WMGetDlgCode(var   msgIn:   TWMGetDlgCode);  
              message   WM_GETDLGCODE;  
      public  
   
      end;  
   
  var  
      frmChild:   TfrmChild;  
   
  implementation  
   
  uses   Unit1;  
   
  {$R   *.dfm}  
   
  procedure   TfrmChild.FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
  begin  
      FreeAndNil(frmChild);  
  end;  
   
  procedure   TfrmChild.FormKeyPress(Sender:   TObject;   var   Key:   Char);  
  begin  
      if   Key   =   #9   then   //   Char(VK_tab)   then  
          if   not   (ActiveControl   is   TDBGrid)   then  
          begin  
              Key   :=   #0;  
              Perform(WM_NEXTDLGCTL,   0,   0);  
          end;  
  end;  
   
  procedure   TfrmChild.WMGetDlgCode(var   msgIn:   TWMGetDlgCode);  
  begin  
      inherited;  
      msgIn.Result   :=   msgIn.Result   or   DLGC_WANTTAB;  
  end;  
   
  procedure   TfrmChild.FormCreate(Sender:   TObject);  
  begin  
  combobox1.Items.AddStrings(screen.fonts);  
      Self.KeyPreview   :=   True;  
  end;  
   
  procedure   TfrmChild.xxxx2Click(Sender:   TObject);  
  begin  
  form1:=tform1.create(self);  
  form1.showmodal;  
  form1.free;  
  end;  
   
  end.  
  //form1就是一个空白的tform;  
  问题点数:0、回复次数:2Top

1 楼lxpbuaa(桂枝香在故国晚秋)回复于 2003-09-02 13:13:23 得分 0

在调用工程和dll的uses部分开头加入ShareMem单元  
   
  ————————————————————————————————————  
  宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。  
  ————————————————————————————————————Top

2 楼kiate(小春子)回复于 2003-09-02 14:25:22 得分 0

在dll中create的Form在dll调用结束之前没有完全释放掉。Top

相关问题

  • 特急:dll注册报错
  • 引用dll后报错
  • dll调用总是报错
  • fastreport在MDI窗体的DLL中报错!
  • 使用DLL时,release正常debug报错。
  • 写DLL时遇到如此报错
  • 一DLL,VB调用是报错:"bad dll caling convention",为什么?
  • DLL编译问题 cl.exe test.cpp /LD报错误!
  • 为何用VC生成的DLL用RUNDLL32运行总是报错?
  • dll中创建adoconnetion,报错'尚未调用CoInitialize',为什么啊

关键词

  • dll
  • 报错
  • mainmenu
  • 调用
  • tobject
  • procedure
  • sender
  • button
  • click

得分解答快速导航

  • 帖主:luck2050

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo