将窗体资源分装到DLL中并且调用 
用Delphi生成DLL并封装窗体的示例
 调用Dll里面的窗体

DLL文件

library Project2;

{ 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'
{Form1};

{$R
*.res}
exports
    Dll_Showform,
    Dll_CreateForm,
    DLL_GetValue,
    DLL_SetTitle;

begin
end.


unit Unit2;

interface

uses
  Windows, Messages, SysUtils,
Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,
Buttons;

type
  TForm1
= class(TForm)
    Memo1:
TMemo;
    BitBtn1: TBitBtn;
  private
    { Private declarations }
  public
    { Public declarations }

  end;

var
    Form1:
TForm1;
    //Ready for DLl Export
list
    procedure
Dll_Showform();stdcall;
    procedure
Dll_Createform(Left,Top,Width,Height:Integer);stdcall;
    function DLL_GetValue():string;stdcall;
    procedure  DLL_SetTitle(text:string); stdcall;
implementation

{$R
*.dfm}

//无参数
procedure Dll_Showform();stdcall;
var frm:TForm1;
begin
   frm:=TForm1.Create(Application);
   frm.Position:=poMainFormCenter;
   frm.ShowModal;
end;

//带参数
procedure
Dll_Createform(Left,Top,Width,Height:Integer);stdcall;
var frm:TForm1;
begin
   frm:=TForm1.Create(Application);
   frm.Left:=Left;
   frm.Top:=Top;
   frm.Width:=Width;
   frm.Height:=Height;
   frm.BorderStyle:=bsNone;

   frm.ShowModal;
end;

//获得返回值
function
DLL_GetValue():string;stdcall;
var
  frm:TForm1;
begin
   Result:='';
   frm:=TForm1.Create(Application);
   frm.Position:=poMainFormCenter;
   if frm.ShowModal = mrok
then
      Result:=frm.Memo1.Lines.Text;
end;

//回调
procedure  DLL_SetTitle(text:string); stdcall;
var frm:TForm1;
begin
   frm:=TForm1.Create(Application);
   frm.Position:=poMainFormCenter;
   frm.Caption:=text;
   frm.ShowModal;
end;

end.


调用Dll

unit Unit1;

interface

uses
  Windows, Messages, SysUtils,
Variants, Classes, Graphics, Controls, Forms,
  Dialogs,
StdCtrls;
//-------------------------------------------------------------------------------
procedure Dll_Showform();stdcall;external 'project2.dll'; //1无参数
直接调用
procedure
Dll_Createform(Left,Top,Width,Height:Integer);stdcall;external 'project2.dll';//2带参数了
function DLL_GetValue():string;stdcall;external 'project2.dll';//3获得返回值
//-------------------------------------------------------------------------------

type
  TfrmMain1 = class(TForm)
    Button1:
TButton;
    Button2:
TButton;
    Button3:
TButton;
    Memo1:
TMemo;
    Button4:
TButton;
    procedure
Button1Click(Sender: TObject);
    procedure Button2Click(Sender:
TObject);
    procedure
Button3Click(Sender: TObject);
    procedure Button4Click(Sender:
TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain1: TfrmMain1;

implementation

{$R
*.dfm}
//------------------------------------------------------------------------------
procedure TfrmMain1.Button1Click(Sender:
TObject);
begin
    Dll_Showform;
end;
//------------------------------------------------------------------------------
procedure TfrmMain1.Button2Click(Sender:
TObject);
var
     x,y:Integer;
begin
    x:=frmMain1.left+Button2.left+8; //Left
    y:=frmMain1.Top+Button2.Top +Button2.Height+28;      //Top
    Dll_Createform(x,y,400,400);
    //  Dll_Createform(0,0,100,200);
end;
//------------------------------------------------------------------------------
procedure TfrmMain1.Button3Click(Sender:
TObject);
begin
     Memo1.Text:=DLL_GetValue;
end;

//------------------------------------------------------------------------------
type
    TSetCaption = procedure(text:string); stdcall;//4回调
procedure
TfrmMain1.Button4Click(Sender: TObject);
var
    pSetTitle:
TSetCaption;
    h:THandle;
begin
    h:=LoadLibrary(PChar('project2.dll'));
    pSetTitle
:= TSetCaption( GetProcAddress(h, PChar('DLL_SetTitle')) );
    if h = 0 then
Exit;
    if
Assigned(pSetTitle) then
        pSetTitle('Hello
World!');
    FreeLibrary(h);
end;

end.

调用Dll里面的窗体的更多相关文章

  1. Delphi程序调用C#.Net编译的DLL并打开窗体(详解)

    Delphi程序调用C#.Net编译的DLL并打开窗体(详解)最近用C#.Net写了一个公用模块, 本以为仅提供给.Net程序使用, 但是领导要求把这些功能提供给旧系统使用, 天啦, 几套旧系统全是D ...

  2. 学习反射例子,调用DLL窗体及方法

    创建类库,并添加新窗体,加入以下方法 public static string setText(string str) { return str; } 编译后把生成的DLL文件放入新项目的bin目录, ...

  3. 【转】C#调用DLL

    C#中如何调用动态链接库DLL(转)     每种编程语言调用DLL的方法都不尽相同,在此只对用C#调用DLL的方法进行介绍.首先,您需要了解什么是托管,什么是非托管.一般可以认为:非托管代码主要是基 ...

  4. C#程序实现动态调用DLL的研究(转)

    摘 要:在<csdn开发高手>2004年第03期中的<化功大法——将DLL嵌入EXE>一文,介绍了如何把一个动态链接库作为一个资源嵌入到可执行文件,在可执行文件运行时,自动从资 ...

  5. C#:控制台程序调用中间库创建窗体

    1.类库项目引用System.Windows.Forms并添加引用后,才可创建窗体. 2.控制台应用程序调用中间库(DLL)中的方法创建窗体:中间类库使用反射下的Assembly加载包含窗体的类库及创 ...

  6. delphi 基础之三 编写和调用dll文件

    delphi 编写和调用dll文件   Windows 的执行文件可以划分为两种形式程序和动态连接库 (DLLs).一般程序运行是用.EXE文件,但应用程序有时也可以调用存储在DLL的函数. 在如下几 ...

  7. 【VB技巧】VB静态调用与动态调用dll详解

    本文“[VB技巧]VB静态调用与动态调用dll详解”,来自:Nuclear'Atk 网络安全研究中心,本文地址:http://lcx.cc/?i=489,转载请注明作者及出处! [[请注意]]:在以下 ...

  8. C#程序实现动态调用DLL的研究[转]

    摘   要: 在< csdn 开发高手> 2004 年第 03 期中的<化功大法——将 DLL 嵌入 EXE >一文,介绍了如何把一个动态链接库作为一个资源嵌入到可执行文件,在 ...

  9. C#程序实现动态调用DLL的研究

    摘 要:在<csdn开发高手>2004年第03期中的<化功大法——将DLL嵌入EXE>一文,介绍了如何把一个动态链接库作为一个资源嵌入到可执行文件,在可执行文件运行时,自动从资 ...

随机推荐

  1. 不重启mysql情况修改参数变量

    地球人都知道,更新mysql配置my.cnf需要重启mysql才能生效,但是有些时候mysql在线上,不一定允许你重启,这时候应该怎么办呢? 看一个例子: 1 2 3 4 5 6 7 8 9 10 m ...

  2. E asy Boo t 6.51 启动易 制作启动光盘的软件(附注册码)

    内建ISO文件生成器,可直接生成可启动ISO文件,并支持N合1优化. -------中文版注册码------- 用户名:中华人民共和国 注册码:2898-5448-5603-BB2D -------英 ...

  3. Fitnesse+RestFixture:Web服务回归测试利器

    RestFixture是Fitness的一个测试REST服务的插件,用于调用标准的http GET/POST等请求方法,并可以用XPath语法和Javascript语法检验http响应.本文介绍安装运 ...

  4. 仿酷狗音乐播放器开发日志十九——CTreeNodeUI的bug修复二(附源码)

    转载请说明原出处,谢谢 今天本来打算把仿酷狗播放列表的子控件拖动插入功能做一下,但是仔细使用播放列表控件时发现了几个逻辑错误,由于我的播放 列表控件是基于CTreeViewUI和CTreeNodeUI ...

  5. python中yield用法

    在介绍yield前有必要先说明下Python中的迭代器(iterator)和生成器(constructor). 一.迭代器(iterator) 在Python中,for循环可以用于Python中的任何 ...

  6. 使用jQuery Mobile实现通讯录

    jQuery Mobile 通讯录 拨打电话作者:方倍工作室 地址: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional/ ...

  7. C++ 我想这样用(七)

    话接前篇,继续基于对象编程语法的剩余部分: 6.类的const成员函数和const对象 const数据成员:跟const常量一样,只是一个在类里(而且是在构造函数里),一个在类外而已,都必须初始化. ...

  8. [HIve - LanguageManual] Transform [没懂]

    Transform/Map-Reduce Syntax SQL Standard Based Authorization Disallows TRANSFORM TRANSFORM Examples ...

  9. MATLAB / Simulink on BeagleBone Black

    转自:beagleboard@googlegroups.com邮件组 作者:kevind I have MATLAB / Simulink working with BeagleBone Black. ...

  10. -exec 与 xargs 的区别

    实地在shell里执行下如下命令就知道区别了: $ find -type f -exec echo {} \; 很明显,exec是对每个找到的文件执行一次命令.从这里可以看出exec的缺点是每处理一个 ...