views:

75

answers:

1

I want to pass constant references to functions in delphi, so I am sure that the referenced object won't change and to save time and memory. So I want to declare a function like

function foo(var const Value : Bar) : Boolean;

however this is not allowed. I thought constant values would be automatically sent as references. However I found out that it is not the case (getting the address of an object before sending it to the function gives me $12F50C and the address of the same object inside the function is $12F564)

What can I do to send constant references?

+1  A: 

Function Foo(Const Value:Bar):Boolean passes the value in the "most efficient" way, for large objects this is usualy by reference but smaller objects tend to get passed by value.

The answers to this question go into more detail...

Note that passing a parameter marked as const doesn't mean it can't be changed, it just means the compiler won't let you directly change it.

JamesB
Thanks, this is very useful to know.
Sambatyon