Delphi 常量和引用
我想传递对 delphi 中函数的常量引用,因此我确信引用的对象不会更改并节省时间和内存。所以我想声明一个类似的函数,
function foo(var const Value : Bar) : Boolean;
但是这是不允许的。我认为常量值会自动作为参考发送。但是我发现事实并非如此(在将对象发送到函数之前获取对象的地址给我 $12F50C,而函数内同一对象的地址是 $12F564)
我可以做什么来发送常量引用?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Function Foo(Const Value:Bar):Boolean
以“最有效”的方式传递值,对于大型对象,这通常通过引用传递,但较小的对象往往通过值传递。这个问题的答案更详细......
请注意,传递标记为 const 的参数并不意味着它不能更改,它只是意味着编译器不会让您直接更改它。
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.