English 中文(简体)
帕斯卡尔支助是否通过职能参数?
原标题:Does Pascal support passing parameters to functions?

我是新到帕斯卡尔的,我正试图起草一个简单的方案,但是,在职能之间出现一种麻烦。 这是我拥有的一点:

program numberConverter;

const
    maxValue = 4999;
    minValue = 1;

var num: integer;

function convertNumeral(number: integer):string;
var j: integer;
begin
if ((number < minValue) OR (number > maxValue)) then
    begin
    writeln(number);
    writeln( The number you enter must be between 1 and 4999. Please try again: );
    read(j);
    convertNumeral := convertNumeral(j);
    end
else 
 if (number >= 1000) then
convertNumeral :=  M  + convertNumeral(number -1000)
{more code here, left it out for space}
end;

begin
    writeln;
    writeln( Enter an integer between 1 and 4999 to be converted: );
    read(num);
    writeln;
    writeln(num);
    writeln(convertNumeral(num));
end.

我的问题是,纸面(converNumeral(num)的数值,主要是Numeral的数值,并没有被转嫁给转基因Numeral的功用,我们想知道Pascal是否这样做。 我的数字是这样,因为我没有宣布人数是一个变数,但当我确实收到汇编错误时,如果发言,我可以完成第二次。 感谢你们的时间。

最佳回答

是的,价值观无疑已传至职能。 我保证num 确实已经通过到<代码>convertNumeral。 在该职能范围内,<代码>> 编号 获取任何价值。 也许,你如何重新观察你方案的行为存在问题。

页: 1 参数通过by Value,因此> 编号。 储存在<代码>num上的价值的copy>;其中有两个不同的变量。 如果符合你的意愿,你可使用<代码>var<>/code>通过参照参数。

每一次互访电话convertNumeral 查阅new instance of number,因此,对的改动(如果有的话)将不会在职能返回打电话者之后出现。 每一份电话都有自己的版本<代码>>>>>j

问题回答

暂无回答




相关问题
Problem with WM_COMMAND on Lazarus/FPC

I have form with MainMenu and I want to intercept when the user selects a command item from a menu. This works in Delphi: type TForm1 = class(TForm) ... // Memo and MainMenu created protected ...

Problem with Splash Screen in Lazarus app

I am porting a Delphi application to FPC/Lazarus and this application shows info in splash screen. When unit has initialization section then this initialization section calls something like: Splash....

Could Free Pascal benefit of something like Apache Maven?

Apache Maven is a very popular build and dependency management tool in the Java open source ecosphere. I did some tests to find out if it can handle compiled Free Pascal / Delphi units and found it ...

TIdHTTP in Indy 10

I used to use Indy back in the Delphi 6 days, and I am playing with Indy 10 now. What I want to do is incredibly simple, but I don t see a simple way of doing it, so I must be missing something. ...

热门标签