Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Delphi equivalent to C++ reference parameters?

Tags:

c++

delphi

How do I write int &a in Delphi?

For example, in C++ it is void ABC(int &a, int &b), but I don't know how to write it in Delphi.

like image 989
user2007672 Avatar asked Jan 24 '13 13:01

user2007672


2 Answers

That is a reference parameter in C++. In Delphi that corresponds to a var parameter.

procedure ABC(var a: Integer; var b: Integer);

The documentation says:

Most parameters are either value parameters (the default) or variable (var) parameters. Value parameters are passed by value, while variable parameters are passed by reference.

like image 161
David Heffernan Avatar answered Oct 09 '22 08:10

David Heffernan


void ABC(int &a, int &b)

would become

procedure ABC(var a: Integer; var b: Integer);

The var keyword indicates that you wish to pass the value by reference, rather than value.

like image 41
Steve Mayne Avatar answered Oct 09 '22 10:10

Steve Mayne