请各位帮我看看下面的代码

dyh506 2003-09-27 04:18:55
我在书上看到一段代码 但有个地方我不明白 请给未给我指点指点
library PenniesLib;
{$DEFINE PENNIESLIB}
uses
SysUtils,
Classes,
PenniesInt;

function PenniesToCoins(TotPennies: word; CoinsRec: PCoinsRec): word; StdCall;
begin
Result := TotPennies; // Assign value to Result(不明白)!!!!
{ Calculate the values for quarters, dimes, nickels, pennies }
with CoinsRec^ do
begin
Quarters := TotPennies div 25;
TotPennies := TotPennies - Quarters * 25;
Dimes := TotPennies div 10;
TotPennies := TotPennies - Dimes * 10;
Nickels := TotPennies div 5;
TotPennies := TotPennies - Nickels * 5;
Pennies := TotPennies;
end;
end;

{ Export the function by name }
exports
PenniesToCoins;
end.
下面是PenniesInt;的定义
unit PenniesInt;
{ Interface routine for PENNIES.DLL }

interface
type

{ This record will hold the denominations after the conversion have
been made }
PCoinsRec = ^TCoinsRec;
TCoinsRec = record
Quarters,
Dimes,
Nickels,
Pennies: word;
end;

{$IFNDEF PENNIESLIB}
{ Declare function with export keyword }

function PenniesToCoins(TotPennies: word; CoinsRec: PCoinsRec): word; StdCall;
{$ENDIF}

implementation

{$IFNDEF PENNIESLIB}
{ Define the imported function }
function PenniesToCoins; external 'PENNIESLIB.DLL' name 'PenniesToCoins';
{$ENDIF}

end.
下面是一个引用
unit MainFrm;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Mask;

type

TMainForm = class(TForm)
lblTotal: TLabel;
lblQlbl: TLabel;
lblDlbl: TLabel;
lblNlbl: TLabel;
lblPlbl: TLabel;
lblQuarters: TLabel;
lblDimes: TLabel;
lblNickels: TLabel;
lblPennies: TLabel;
btnMakeChange: TButton;
meTotalPennies: TMaskEdit;
procedure btnMakeChangeClick(Sender: TObject);
end;

var
MainForm: TMainForm;

implementation
uses PenniesInt; // Use an interface unit

{$R *.DFM}

procedure TMainForm.btnMakeChangeClick(Sender: TObject);
var
CoinsRec: TCoinsRec;
TotPennies: word;
begin
{ Call the DLL function to determine the minimum coins required
for the amount of pennies specified. }
TotPennies := PenniesToCoins(StrToInt(meTotalPennies.Text), @CoinsRec);
with CoinsRec do
begin
{ Now display the coin information }
lblQuarters.Caption := IntToStr(Quarters);
lblDimes.Caption := IntToStr(Dimes);
lblNickels.Caption := IntToStr(Nickels);
lblPennies.Caption := IntToStr(Pennies);
end
end;

end.
不明白的是Result := TotPennies; // Assign value to Result
他返回这样一个函数值是干什么呢?我看在后面的函数引用中他要的是记录域中的值而已啊
...全文
40 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
killme2008 2003-09-27
  • 打赏
  • 举报
回复
楼上的大哥都说了
我也在学动态连接库问题,一起进步
lxhong1980 2003-09-27
  • 打赏
  • 举报
回复
学习
mengxiang5160 2003-09-27
  • 打赏
  • 举报
回复
程序必须预致一个返回值
在程序正常的情况下,返回你要返回的值
mengjj 2003-09-27
  • 打赏
  • 举报
回复
函数必须要有返回值的
dyh506 2003-09-27
  • 打赏
  • 举报
回复
up

5,930

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧