Re: [fpc-pascal] Re: Correct use of var in function calls?

2011-02-07 Thread michael . vancanneyt
On Sun, 6 Feb 2011, Florian Klämpfl wrote: Am 06.02.2011 18:53, schrieb Bo Berglund: So in summary: If the called method changes the length of teh dynamic array it must be passed as a var, otherwise the length change will be lost when exiting the method. I'd even propose that one uses var

[fpc-pascal] Re: Correct use of var in function calls?

2011-02-06 Thread Bo Berglund
On Sat, 05 Feb 2011 15:51:37 +0100, Florian Klaempfl flor...@freepascal.org wrote: Am 05.02.2011 10:46, schrieb Bo Berglund: But that is not what I am doing at all, so I can stick with a simple: FillArr(Arr: TByteArr) and be sure that I will not get back a different array, but instead get

Re: [fpc-pascal] Re: Correct use of var in function calls?

2011-02-06 Thread Florian Klämpfl
Am 06.02.2011 18:53, schrieb Bo Berglund: So in summary: If the called method changes the length of teh dynamic array it must be passed as a var, otherwise the length change will be lost when exiting the method. I'd even propose that one uses var as soon as he plans to change the array. It

[fpc-pascal] Re: Correct use of var in function calls?

2011-02-05 Thread Bo Berglund
On Fri, 4 Feb 2011 19:10:33 +0100, Jonas Maebe jonas.ma...@elis.ugent.be wrote: On 04 Feb 2011, at 16:25, Bo Berglund wrote: OK, what will happen if I have a declaration like this: function TSSCommBuf.Read(var Data: TByteArr): boolean; as opposed to function TSSCommBuf.Read(Data:

Re: [fpc-pascal] Re: Correct use of var in function calls?

2011-02-05 Thread michael . vancanneyt
On Sat, 5 Feb 2011, Bo Berglund wrote: On Fri, 4 Feb 2011 19:10:33 +0100, Jonas Maebe jonas.ma...@elis.ugent.be wrote: On 04 Feb 2011, at 16:25, Bo Berglund wrote: OK, what will happen if I have a declaration like this: function TSSCommBuf.Read(var Data: TByteArr): boolean; as opposed to

[fpc-pascal] Re: Correct use of var in function calls?

2011-02-05 Thread Bo Berglund
On Sat, 5 Feb 2011 09:24:44 +0100 (CET), michael.vancann...@wisa.be wrote: No. Someone misunderstands the concept of dynamic array here. A dynamic array is a pointer to an array in memory. So when passing a dynamic array to a function, you are, in fact, passing a pointer. So is there a

Re: [fpc-pascal] Re: Correct use of var in function calls?

2011-02-05 Thread Michael Van Canneyt
On Sat, 5 Feb 2011, Bo Berglund wrote: On Sat, 5 Feb 2011 09:24:44 +0100 (CET), michael.vancann...@wisa.be wrote: No. Someone misunderstands the concept of dynamic array here. A dynamic array is a pointer to an array in memory. So when passing a dynamic array to a function, you are, in

Re: [fpc-pascal] Re: Correct use of var in function calls?

2011-02-05 Thread Florian Klaempfl
Am 05.02.2011 10:46, schrieb Bo Berglund: But that is not what I am doing at all, so I can stick with a simple: FillArr(Arr: TByteArr) and be sure that I will not get back a different array, but instead get my array filled as requested... As soon as you call SetLength, this will break

[fpc-pascal] Re: Correct use of var in function calls?

2011-02-04 Thread leledumbo
FPC is Delphi compatible regarding this. Dynamic arrays are passed by reference, so you don't need var here. Please be aware when you directly play with dynamic array contents, since it's actually a pointer to a record in heap and it's reference counted. -- View this message in context:

[fpc-pascal] Re: Correct use of var in function calls?

2011-02-04 Thread Bo Berglund
On Fri, 4 Feb 2011 06:41:24 -0800 (PST), leledumbo leledumbo_c...@yahoo.co.id wrote: FPC is Delphi compatible regarding this. Dynamic arrays are passed by reference, so you don't need var here. Please be aware when you directly play with dynamic array contents, since it's actually a pointer to a

Re: [fpc-pascal] Re: Correct use of var in function calls?

2011-02-04 Thread Jonas Maebe
On 04 Feb 2011, at 16:25, Bo Berglund wrote: OK, what will happen if I have a declaration like this: function TSSCommBuf.Read(var Data: TByteArr): boolean; as opposed to function TSSCommBuf.Read(Data: TByteArr): boolean; Will they be equivalent or will there be an extra layer of