没有接触过DELPHI的DLL编程,马上就要用了,请问各位高手,DELPHI中DLL编程的原理,操作步骤.它与平常编写程序有什么不同。希望能详尽一点。有分!!
谢了
谢了
解决方案 »
- 急!delphi中,Pascal语言有没有类似SQL语言中like的关键字或者函数
- 测试...
- 请问在鼠标钩子定义函数dll中怎么获取光标所在控年的句柄啊
- 《幫忙》誰能發一個delphi範例文件customer.db給我(這個文件大家都有)
- 为什么在调用存储过程时,提示窗体出错!!
- 用DataModule有什么优点?数据处理速度会比用Form更快吗?
- 怎样让Adoconnect控件彻底与数据库断开
- InstallShield中文版语言包,安装以后生成的安装程序却不能运行
- 如何一个类是否有某项属性?
- 遇到这问题,真伤脑筋.您说该......
- Delphi6.0企业版安装程序
- 我用ADOQuery执行 insert 或 update 语句,语法完全正确,为什么还系统跳出提示说‘语法错误’呢,百思不得其解。晕 ~~
关键词:DELPHI DLL 动态连接库 一* 引言出自PASCAL的DELPHI语言以其崭新的特点在众多的语言工具中成为一枝独秀而受到大家的青睐,这些特点如在其中把一切视为“对象”,从而编写面向对象的程序可以重复使用以前的成果;“可视化”编程环境提供图形化工具供用户创建和调整程序中的可视部分;尤为突出的是起一流的代码编辑器效率和极易扩充的开发平台(可使用各种VBX版本)。动态连接库(DLL)允许WINDOWS应用程序分享资源和代码,DLL是一个能够被所有WINDOWS程序共享的可执行模块。DLL是在运行期间被连接的(是一种动态的连接),而C语言的运行函数库是在可执行文件生成期间通过连接程序连接的(是一种静态的连接)。 熟悉VB的同志都知道,VB可以调用DLL,但其本身不能创建DLL,而运用DELPHI则可以方便地定制DLL,并调用其例程。二·创建DLLDELPHI把一个项目编译成一个DLL是相当简单的。 首先,从这个项目中删去除项目单元(.DPR文件)之外的所有单元,然后,对这个项目单元实施以下步骤:
1·把该单元顶部的保留字program改为library。
2·从该项目的uses子句中删去表单单元。
3·在该单元的底部删去begin和end之间所有程序代码。
4·在该单元底部的begin之前加入一个export小节。下面的代码(MyDll.Dpr)即为构造的一个DLL:{ MYDLL.DPR}
library Mydll;
uses
dialogs;
function Hobbit (value:integer): string; export;
begin
case value of
1: result := 'Frodo';
2: result := 'Samwise';
3: result := 'Pippin';
4: result := 'Meriadoc';
else
result := 'Must be an Orc!';
end;
end;function Larger (Val1, Val2: integer): integer; export;
begin
if Val1 > Val2 then
result := Val1
else if Val2 > Val1 then
result := val2
else
result := 0;
end;procedure Elephants;export;
begin
ShowMessage ('Pink Elephants on Parade');
end;
exports
Hobbit index 1,
Larger index 2,
Elephants index 3;
begin
end.下面的代码(MYIMPORT。PAS)是为MYDLL创建引入程序单元:{Import unit for MyDll.Dll}
unit Myimport;
interface
function Hobbit (value:Integer):string;
function Larger (val1,val2:Integer): Integer;
procedure Elephants;implementation
function Hobbit (value:Integer):string; external 'Mydll' index 1;
function Larger (val1,val2:Integer): Integer; external 'Mydll' index 2;
procedure Elephants; external 'Mydll' index 3;
end.
通过DELPHI的Compile\Build All选项,将以上代码编译成DLL(MyDll.Dll),以后我们就可以像调用任何其他函数或过程一样来调用这些例程了。
三·例成调用在项目的一个表单中加入三个按钮和一个Memo部件,下面即为调用上述DLL的DEKPHI应用程序代码:{ Unit.pas}
unit Unit1;interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, myimport;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.lines.add (Hobbit(5));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo1.lines.add (IntToStr(Larger(12,25)) + ' is larger than 12');
end;procedure TForm1.Button3Click(Sender: TObject);
begin
Elephants;
end;
end.{ myimport.pas}
unit Myimport;
interfacefunction Hobbit (value:Integer):string;
function Larger (val1,val2:Integer): Integer;
procedure Elephants;
implementation
function Hobbit (value:Integer):string; external 'Mydll' index 1;
function Larger (val1,val2:Integer): Integer; external 'Mydll' index 2;
procedure Elephants; external 'Mydll' index 3;
end.
2.写函数或者过程
3.exports出函数或者过程名