Link to home
Start Free TrialLog in
Avatar of koger
koger

asked on

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
Avatar of Lee_Nover
Lee_Nover

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;
ASKER CERTIFIED SOLUTION
Avatar of robert_marquardt
robert_marquardt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.