T
terry_zhou82
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls
type
TForm1 = class(TForm)
Edit1: TEdit
Button1: TButton
procedure Button1Click(Sender: TObject)
private
function caculate(n:integer):integer
{ Private declarations }
public
{ Public declarations }
end
var
Form1: TForm1
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject)
begin
edit1.Text :=inttostr(caculate(10))
end
function TForm1.caculate n: integer): integer
begin
n:=n*10
end
end.
照规矩,按照参数原则,我是不是应该在函数参数前添加VAR ? 但是实际使用却出现以下错误。不加VAR倒是可以运行正常,什么原因啊?
[Error] Unit1.pas(30): Types of actual and formal var parameters must be identical
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
是什么原因啊,不过不加VAR,编译可以通过,但是计算出来的结果不对,应该是100,而他却是142768?有哪位大大知道吗?急,小弟在线等。
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls
type
TForm1 = class(TForm)
Edit1: TEdit
Button1: TButton
procedure Button1Click(Sender: TObject)
private
function caculate(n:integer):integer
{ Private declarations }
public
{ Public declarations }
end
var
Form1: TForm1
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject)
begin
edit1.Text :=inttostr(caculate(10))
end
function TForm1.caculate n: integer): integer
begin
n:=n*10
end
end.
照规矩,按照参数原则,我是不是应该在函数参数前添加VAR ? 但是实际使用却出现以下错误。不加VAR倒是可以运行正常,什么原因啊?
[Error] Unit1.pas(30): Types of actual and formal var parameters must be identical
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
是什么原因啊,不过不加VAR,编译可以通过,但是计算出来的结果不对,应该是100,而他却是142768?有哪位大大知道吗?急,小弟在线等。