msd 5 Posted February 8, 2023 Hello, If I want to set all params of Delphi function to be const (because of small amount of memory) do I need to define it as: function FnName(const varA: string; const varB: integer; const varC: boolean = false): boolean; OR function FnName(const varA: string; varB: integer; varC: boolean = false): boolean; Thanks in advance... Share this post Link to post
Brandon Staggs 278 Posted February 8, 2023 (edited) The first, because in the latter, you are saying the first parameter is const but the others are going to get local copies. Also, for strings, there is no memory issue here you are solving. I really doubt any memory issue can exist with integer or boolean parameters. If so, probably you need to look at some kind of data structure you pass by reference. Strings are copy-on-write. In this case you are just telling the compiler not to allow setting a new value to the string in that function. You are just preventing the reference count from being incremented at the beginning of the function call, you are not changing how the compiler passes the string reference. Edited February 8, 2023 by Brandon Staggs Share this post Link to post
programmerdelphi2k 237 Posted February 8, 2023 I think that better way would be read the EMB explains https://docwiki.embarcadero.com/RADStudio/Sydney/en/Parameters_(Delphi) after, this... each case it's a case (in special case) Share this post Link to post