易截截图软件、单文件、免安装、纯绿色、仅160KB

Delphi 的 Dll 函数的 调用


一、Dll建立
(一)DLL项目的建立
library mydll;
 
uses
base in 'base.pas';
 
exports
Triple name 'Tr';
 
{$R *.res}
 
begin
end.
 
(二)函数单元
unit base;
 
interface
 
uses windows;
 
function Triple(N:integer):integer;stdcall;
 
implementation
 
function Triple(N:integer):integer;stdcall;
begin
result:=n*3;
end;
 
end.
 
 
二、静态调用
 
unit Unit1;
 
interface
 
uses
Windows, SysUtils, Controls, Forms,
StdCtrls, Classes;
 
type
TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
private
    { Private declarations }
public
    { Public declarations }
end;
 
var
Form1: TForm1;
 
implementation
 
const
gdi32='mydll';
function triple(n:integer):integer;stdcall;external gdi32 name 'Tr';
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=inttostr(triple(10));
end;
 
end.
 
三、动态调用
unit Unit2;
 
interface
 
uses
Windows, SysUtils, Controls, Forms,
StdCtrls, Classes;
 
type
TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
private
    { Private declarations }
public
    { Public declarations }
end;
 
var
Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
type
   Taddc=function(n:integer):integer;stdcall;//定义函数指针
var
Handle:Thandle;
addc:Taddc;
begin
Handle:=LoadLibrary('mydll.dll');//加载mydll
if Handle>32 then
begin
   @addc:=GetProcAddress(Handle,'Tr'); //取Tr函数入口地址,大小写敏感。Tr为mydll中的Triple的exports 的name命名
   if @a


相关文档:

delphi TStringList的用法

delphi TStringList的用法
TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的。
常规的用法大家都知道,现在来讨论它的一些高级的用法。
先把要讨论的几个属性列出来:
1、CommaText
2、Delimiter & DelimitedText
3、Names & Values & ValuefromIndex
先看第一个:CommaText。怎么 ......

Delphi 字符串操作

常忘记,在此做笔记。
这几个函数都包含在StrUtils中,所以需要uses StrUtils; 
假设字符串是 Dstr := ’Delphi is the BEST’, 那么 
LeftStr(Dstr, 5) := ’Delph’ 
MidStr(Dstr, 6, 7) := ’ ......

DELPHI加密字串(异或运算加密)

这个本来我我在DELPHI盒子看到的,后来我对其作了一点修改,这里上全部代码,可以直接用
首先有两个自定的转换函数:
function myStrToHex(s:string):string; //字串转16进制
var
TmpStr:string;
i:integer;
begin
TmpStr:='';
for i:=1 to Length(s)do
TmpStr:=TmpStr+IntToHex(ord(s[i]),2);
Res ......

Delphi 调用 C#的Webservice 不能传入参数


Delphi7 调用 C#的Webservice 不能传入参数
解决办法:
在Delphi导入WSDL后生成的单元的最后一行,即initialization里的初始化端口的代码中加入代码
InvRegistry.RegisterInvokeOptions(TypeInfo(接口名), ioDocument);
即可
 
 
......

DELPHI 查找,增加,修改,删除

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls;
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Button ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号