library Project2;
{$define pennieslib}{ 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;
penniesint;
function penniestocoins(toppennies:word;coinsrec:pcoinsrec):word;stdcall;
begin
result:=toppennies;
with coinsrec^ do
begin
quarters:=toppennies div 25;
toppennies:=toppennies-quarters*25;
dimes:=toppennies div 10;
toppennies:=toppennies-dimes*10;
nickels:=toppennies div 5;
toppennies:=toppennies-nickels*5;
pennies:=toppennies;
end; exports penniestocoins;
{$R *.res}
begin
end.我看 delphi5 开发人员指南 的DLL 可是看不懂,请教各位老大几个问题:
下面是我照抄一段代码:
问题1:
{$define pennieslib} 是什么,怎么来的?
问题2:penniesint ,是什么,可以不先定义吗?
问题3:coinsrec:pcoinsrec 的 pcoinsrec 是什么类型?
问题4:我上面写的格式对吗?
{$define pennieslib}{ 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;
penniesint;
function penniestocoins(toppennies:word;coinsrec:pcoinsrec):word;stdcall;
begin
result:=toppennies;
with coinsrec^ do
begin
quarters:=toppennies div 25;
toppennies:=toppennies-quarters*25;
dimes:=toppennies div 10;
toppennies:=toppennies-dimes*10;
nickels:=toppennies div 5;
toppennies:=toppennies-nickels*5;
pennies:=toppennies;
end; exports penniestocoins;
{$R *.res}
begin
end.我看 delphi5 开发人员指南 的DLL 可是看不懂,请教各位老大几个问题:
下面是我照抄一段代码:
问题1:
{$define pennieslib} 是什么,怎么来的?
问题2:penniesint ,是什么,可以不先定义吗?
问题3:coinsrec:pcoinsrec 的 pcoinsrec 是什么类型?
问题4:我上面写的格式对吗?
{$define pennieslib} 是条件编绎语句。问题二:
Penniesint 是penniesint.pas 文件问题三:
coninsrec 声明的是penniesit.pas里面的记录数据类型
它的原型是
PConinsRec = ^TConinsRec;
TConisRec = Record
Quarters,
Dimes,
Nickels,
Pennies: Word;
end;
它的类型是指针,具体指向记录类型TConisRec,这里是用指针来做形参...