开发者

Delphi constants and references

开发者 https://www.devze.com 2022-12-23 19:22 出处:网络
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

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 befor开发者_Go百科e 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号