Solved

const pass by reference

Posted on 2002-04-25
3
467 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
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 150 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now