Pascal Syntax Error

家住魔仙堡 提交于 2019-12-13 12:51:08

问题


I have the following function in my program:

function Getrand(rStart,rEnd:Integer): Integer;
var
diff: Integer;

begin
diff := rEnd - rStart;

Getrand := Random(diff) + rStart;
end;

When I try to compile the program, I get this error:

Failed when compiling
Line 27: [Error] (27:9): Invalid number of parameters in script 

What am I doing wrong?


回答1:


Perhaps your flavour of Pascal doesn't support the traditional return value syntax. Try Result := … instead of Getrand := ….




回答2:


you can use

Exit(Random(diff) + rStart)

instead. But keep in mind that if you do that it will exit from function after returning the value.




回答3:


You need to write Getrand(Random(diff),rStart); to send variables to function



来源:https://stackoverflow.com/questions/4965977/pascal-syntax-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!