(一)通过向导DLL Wizard新建一个动态链接库,取名为:DLLPro.dpr。说明:当在DLL工程文件中使用了String类型时,要有 uses ShareMem ,不过建议使用PChar类型。其代码如下:

library DLLPro;            //编译生成DLLPro.dll文件。

uses
ActiveX,
Forms,
Windows,
SysUtils,
Classes,
DLLUnt in 'DLLUnt.pas'; {$R *.res} var
DllApp:TApplication; //全局变量DLLApp默认初始化,即,DLLApp:=Application. procedure CreateForm1(app:TApplication;parentform: TForm); export;stdcall;
var
Form1: TForm1;
begin
CoInitialize(nil);
try
Application:=app;
Form1:=Tform1.Create(parentform);
form1.MyParentForm:= parentform; //MyParentForm在DLLUnt.pas中定义为公共变量
form1.myparentApplication:=app; //MyParentApplication在DLLUnt.pas中定义为公共变量 Form1.Show;
finally
CoUninitialize;
end;
end; procedure ExitDll(Reason:Integer);
begin
if Reason = DLL_PROCESS_DETACH then // DLL_PROCESS_DETACH值在DLL死亡时执行。
begin
Application:=DllApp;
end;
end; exports
CreateForm1; begin
DllApp:=Application; //该语句可以省略。
DllProc:=@ExitDll; //变量DllProc是SysUtils单元的一个Pointer类型的变量。
end. <===============================================================================> (二)创建DLL(动态链接库)的单元文件,取名为:DLLUnt.pas,该单元文件有与其配套的窗体文件DLLUnt.dfm;有一个ADOConnection1组件,必须定义在TForm1类中,否则编译时出错:Access Violence其部分代码如下: unit DLLUnt; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons,ADODB,DB; type
TForm1 = class(TForm)
Panel0: TPanel;
GroupBox1: TGroupBox;
Panel1: TPanel;
Panel2: TPanel; ……………… CheckBox891: TCheckBox;
Edit1: TEdit;
SpeedButton1: TSpeedButton;
ADOConnection1: TADOConnection;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure SpeedButton1Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MyParentForm: TForm;
MyParentApplication: TApplication;
end; var
Form1: TForm1; implementation {$R *.dfm} ……………… procedure TForm1.SpeedButton1Click(Sender: TObject);
var
query:TADOquery;
Count,I,RedNum,J,CheckNum:integer;
RedName,LabName:string;
begin
if (edit1.Text='')or(length(edit1.Text)<)or(StrToFloat(edit1.Text)<) then
begin
showmessage('Error');
exit;
end;
query:=Tadoquery.Create(nil);
query.Connection:=ADOConnection1;
query.Close;
query.SQL.Clear;
query.SQL.Add('select * from gyWinNum where Id>='+quotedStr(edit1.Text)+' order by Id ');
query.Open;
Count:=;
CheckNum:=;
while (Not query.Eof)and(Count<) do ……………… end. <===============================================================================> (三)创建项目主窗体的工程文件,取名:MainForm.dpr,其代码如下: program MainPro; //编译生成MainPro.exe文件。 uses
Forms,
MainUnt in 'MainUnt.pas' {MainForm}; {$R *.res} begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end. <================================================================================> (四)创建项目主窗体的单元文件,取名:MainUnt.pas,其代码如下: unit MainUnt; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ADODB; //由于被调文件DLLPro.dll中含义数据集控件,在这里必须要有声明。 type
TMainForm = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end; var
MainForm: TMainForm; implementation
{$R *.dfm} procedure CreateForm1(app: TApplication;parentform: TForm);stdcall; external'DLLPro.dll'; procedure TMainForm.Button1Click(Sender: TObject);
begin
CreateForm1(Application,self);
end; end. <================================================================================> 另外:创建项目主窗体的单元文件,取名:MainUnt.pas,其代码也可以如下: unit MainUnt; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,adodb; type
TMainForm = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject); private
{ Private declarations }
public
{ Public declarations }
end;
T_CreateForm1=procedure(app: TApplication;parentform: TForm);stdcall; //定义T_CreateForm1类型 var
MainForm: TMainForm; implementation
{$R *.dfm} procedure TMainForm.Button1Click(Sender: TObject);
var
dllHandle: THandle;
Procaddr: FarProc;
CreateForm1: T_CreateForm1;
begin
dllHandle:=LoadLibrary('DLLPro');
Procaddr:=GetProcAddress(dllHandle,'CreateForm1');
if Procaddr <> nil then
begin
CreateForm1:=procaddr; //过程名,标识它的入口地址,是过程指针。
CreateForm1(Application,self);
end;
end; end. 到此为止,结束。 好文要顶 关注我 收藏该文
 

调用DLL窗体-Delphi实例的更多相关文章

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

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

  2. C++ 生成 dll 和调用 dll 的方法实例(转)

    1)生成dll 建立两个文件 xxx.h , xxx.cpp xxx.h内容如下: #ifdef BUILD_XXX_DLL#define EXPORT __declspec(dllexport)#e ...

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

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

  4. Delphi 动态与静态调用DLL(最好的资料)

    摘要:本文阐述了 Windows 环境下动态链接库的概念和特点,对静态调用和动态调用两种调用方式作出了比较,并给出了 Delphi 中应用动态链接库的实例. 一.动态链接库的概念    动态链接库(  ...

  5. 调用Dll里面的窗体

    将窗体资源分装到DLL中并且调用 用Delphi生成DLL并封装窗体的示例 调用Dll里面的窗体 DLL文件 library Project2;{ Important note about DLL m ...

  6. 在Delphi中静态调用DLL

    在Delphi中静态调用DLL top 调用一个DLL比写一个DLL要容易一些.首先给大家介绍的是静态调用方法,稍后将介绍动态调用方法,并就两种方法做一个比较.同样的,我们先举一个静态调用的例子. u ...

  7. ASP 调用dll(VB)及封装dll实例

    ASP调用dll及封装dll实例,封装为dll可以提供运行效率,加密代码. 打开VB6,新建ActiveX DLL 2.在工程引用中加入Microsoft Active Server Pages Ob ...

  8. Delphi调用SQL分页存储过程实例

    Delphi调用SQL分页存储过程实例 (-- ::)转载▼ 标签: it 分类: Delphi相关 //-----下面是一个支持任意表的 SQL SERVER2000分页存储过程 //----分页存 ...

  9. delphi编写与调用DLL(delphi7下测试通过)

    http://blog.sina.com.cn/s/blog_4dbbf76f01000anz.html delphi编写DLL 下面在delphi中编写一个简单的dll,在该dll中只有一个max函 ...

随机推荐

  1. Linux设置桌面图标 (双击运行jar包)

    Ubuntu平台 预备条件: 1)平台是Gridion上的Ubuntu 2)安装了JRE (版本如下) 3)在IDE(我用的是IDEA)打包成可运行的jar文件 设置步骤: 1)新建.desktop文 ...

  2. Spring IOC(七)类型推断

    Spring IOC(七)类型推断 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Spring 容器中可以根据 bean ...

  3. Maximum Subarray LT53

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...

  4. Permutation Sequence LT60

    The set [1,2,3,...,n] contains a total of n! unique permutations. By listing and labeling all of the ...

  5. spring 学习 二 IOC/DI

    中文名称:控制反转 英文名称:( Inversion of Control ) 1 控制反转作用: 一般在编写java程序时,需要程序员自己创建对象的实例,例如 A a=new A();语句,就是程序 ...

  6. mysql 初始密码、修改密码

    新装MySQL,进不去,找不到网上说的什么临时密码,也没有见到放临时密码的文件,历经坎坷,终解决,,在此记录,谨防下次忘记,在此感谢原作者博文 系统 Ubuntu18.04 mysql Ver 14. ...

  7. mysql之索引查询2

    一 索引的创建 索引减慢了 写的操作,优化了读取的时间 index:普通索引,加速了查找的时间. fulltext:全文索引,可以选用占用空间非常大的文本信息的字段作为索引的字段.使用fulltext ...

  8. 2018.12.30 poj3734 Blocks(生成函数)

    传送门 生成函数入门题. 按照题意构造函数: 对于限定必须是出现偶数次的颜色:1+x22!+x44!+...=ex+e−x21+\frac {x^2}{2!}+\frac {x^4}{4!}+...= ...

  9. 关于微信小程序中组件和页面对全局样式的继承性

    1.组件只能继承全局样式中的font和color(backgroundcolor不继承) 2.页面可以继承全局样式中所有样式

  10. 清理docker大日志文件

    1.进入容器文件的存放目录 ,并查看某一个容器的文件大小 [root@auto ~]# [root@auto ~]# cd /var/lib/docker/containers [root@auto ...