CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

怎么把窗体编译成dll,怎么调用窗体dll?

楼主yball(yball)2002-07-25 09:05:55 在 Delphi / VCL组件开发及应用 提问

不如unit1.pas是主窗体,要把unit2.pas放入unit2.dll,并且在unit1.pas可以调用unit2? 问题点数:100、回复次数:6Top

1 楼careerist()回复于 2002-07-25 09:12:13 得分 0

先把unit2.pas加入到unit2.dll项目中,要在unit2.pas中写一段类似于ShowForm的接口函数.  
  再在unit1.pas中调用unit2.pas中的接口函数.Top

2 楼yball(yball)回复于 2002-07-25 09:18:51 得分 0

给个例子!谢谢!如果搞定的话,再加100分!Top

3 楼toplor(霜天晓竹)回复于 2002-07-25 09:26:15 得分 100

首先将Form2编进DLLPro.dll中,怎么编@##¥¥%^&J*,代码如下:  
   
  ////////////////////////DLLPro.dpr/////////////////////////////////  
  library   DLLPro;  
   
  {   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  
      SysUtils,  
      Classes,  
      Unit2   in   'Unit2.pas'   {Form2};  
   
  {$R   *.res}  
   
  exports  
      myShowForm2,  
      myCloseForm2;  
   
  begin  
  end.  
   
  ///////////////////////Unit2.pas///////////////////////////////////  
  unit   Unit2;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs;  
   
  type  
      TForm2   =   class(TForm)  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
  {var  
      Form2:   TForm2;}  
   
  function   myShowForm2(AHandle:THandle):longint;stdcall;  
  procedure   myCloseForm2(AFormRef:longint);stdcall;  
   
  implementation  
   
  {$R   *.dfm}  
   
  function   myShowForm2(Ahandle:Thandle):longint;  
  var  
      form2:Tform2;  
  begin  
      application.Handle:=AHandle;  
      form2:=tform2.Create(application);  
      form2.Show;  
      result:=longint(form2);  
  end;  
   
  procedure   myCloseForm2(AformRef:longint);  
  begin  
      if   AFormRef>0then  
          Tform2(AformRef).Release;  
  end;  
   
  end.  
     
   
  编绎成功后,在任何工程中都可以调用DllPro.dll,显示非模式的Form2,如下:  
  ////////////////////////Project1.dpr/////////////////////////////  
  program   Project1;  
   
  uses  
      Forms,  
      Unit1   in   'Unit1.pas'   {Form1};  
   
  {$R   *.res}  
   
  begin  
      Application.Initialize;  
      Application.CreateForm(TForm1,   Form1);  
      Application.Run;  
  end.  
   
  ///////////////////////////Unit1.pas///////////////////////////////  
  unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   StdCtrls;  
   
  type  
      TForm1   =   class(TForm)  
          Button1:   TButton;  
          procedure   Button1Click(Sender:   TObject);  
          procedure   FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
  var  
      Form1:   TForm1;  
      FormRef:longint;  
   
  function   myShowForm2(AHandle:THandle):longint;stdcall;  
  procedure   myCloseForm2(AFormRef:longint);stdcall;  
   
  implementation  
   
  function   myShowForm2;external   'DLLPro.dll';  
  procedure   myCloseForm2;external   'DllPro.dll';  
   
  {$R   *.dfm}  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
      FormRef:=myShowForm2(application.Handle);  
  end;  
   
  procedure   TForm1.FormClose(Sender:   TObject;   var   Action:   TCloseAction);  
  begin  
      myCloseForm2(FormRef);  
  end;  
   
  end.  
   
   
  -------------------------------------------------------------------  
  风过西窗客渡舟船无觅处  
  年年一川新草遥看却似旧Top

4 楼gmc007(江西的佬表)回复于 2002-07-25 09:35:24 得分 0

如果你了解一点COM,我想这个问题很简单。  
  Top

5 楼careerist()回复于 2002-07-25 09:43:32 得分 0

DLL文件:  
  library   Main;  
   
  uses  
      Main   in   'Main.pas'   {fmMain};  
   
  exports  
      ShowForm;  
   
  {$R   *.res}  
   
  begin  
  end.  
   
  PAS文件:  
  unit   Main;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,   Dialogs,   hbDialog,   DB,   DBClient,   MConnect,   StdCtrls,   Buttons,   ActiveX;  
  type  
      ...  
  var  
      ...  
  procedure   ShowForm(可以加些参数);   stdcall;  
   
  implementation  
   
  procedure   ShowForm();  
  begin  
      try  
          ShowModal;  
      finally  
          Free;  
      end;  
  end;  
   
   
  调用DLL中的函数:  
   
  procedure   TForm2.Button1Click(Sender:   TObject);  
  var  
      aHandle:   THandle;  
      ShowForm:   procedure();   stdcall;  
  begin  
      aHandle   :=   LoadLibrary(Main.DLL');  
      if   aHandle   <>   0   then  
          @ShowForm   :=   GetProcAddress(aHandle,'ShowForm');  
      if   @ShowForm   <>   nil   then  
      begin  
          try  
              ShowForm();  
          finally  
              FreeLibrary(aHandle);  
          end;  
      end;  
  end;  
  Top

6 楼yball(yball)回复于 2002-07-25 10:03:54 得分 0

ok,结帖加分!150+50Top

7 楼stiwin((忙碌))回复于 2002-07-25 10:12:37 得分 0

在Dll文件中uses你的窗体Top

8 楼xjl(...)回复于 2002-07-25 10:29:14 得分 0

标记一下Top

相关问题

  • dll中的窗体调用
  • 编译成DLL能否带窗体?
  • 网页能编译成DLL,在另一个项目中调用这个DLL文件中的用户控件或窗体吗?请帮助我.急!!!
  • 在DLL中怎样调用MDI窗体
  • 求DLL中调用窗体的例子
  • 如何调用DLL中的窗体
  • 调用DLL中窗体时的问题
  • 关于调用dll中的窗体
  • VC.NET如何调用VC6.0编译的DLL?
  • C# 编译dll VB调用 可以吗

关键词

  • 函数
  • dll
  • 窗体
  • showform
  • 调用
  • unit
  • ahandle
  • pas
  • dllpro
  • exports

得分解答快速导航

  • 帖主:yball
  • toplor

相关链接

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

广告也精彩

反馈

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