?
Solved

const pass by reference

Posted on 2002-04-25
3
Medium Priority
?
474 Views
Last Modified: 2012-05-04
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
Comment
Question by:koger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6970059
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
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 450 total points
ID: 6970444
const Parameter in Delphi uses call by reference automatically if the variable is bigger than 4 Bytes.
0
 
LVL 3

Expert Comment

by:rondi
ID: 6970610
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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question