• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

const pass by reference

Hi

how is it possible to pass a paramter to a function as a const reference.

In C it would look something like this

void Proc(const int &i)
{}

Please don't tell me this is one of the rare cases where C is outrunning Delphi
0
koger
Asked:
koger
1 Solution
 
Lee_NoverCommented:
you can do it
for instance you can have :

procedure Proc(const I: Integer);

or

procedure DoStuff(const List: TList);

you can do anything with List except assign another value to it
so you can do:
List.Capacity:=x;

but you can't do:
List:=TList.Create;
or
List:=SomeOtherList;
0
 
robert_marquardtCommented:
const Parameter in Delphi uses call by reference automatically if the variable is bigger than 4 Bytes.
0
 
rondiCommented:
The const reserved word in method parameters means the compiler should not create a local copy of the parameter, coz the parameter won't be modified.

If you wanna pass stuff by reference, i.e pointing to the
actual variable you'd use the var specifier.

eg.
procedure Proc(var I: Integer);

Although there's no real gain here coz you're still
passing 32 bits.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now