Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-09 Thread Fred van Stappen
> So: don't touch it! ;) > > Regards, > Sven Yep, many thanks for that clear answer. ;-) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pas

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-09 Thread Sven Barth
On 09.02.2014 15:10, Fred van Stappen wrote: > Date: Sun, 9 Feb 2014 13:08:16 +0100 > From: freepas...@ypa-software.de > To: fpc-pascal@lists.freepascal.org > Subject: Re: [fpc-pascal] High() and Low() for empty dynamic arrays > > Am 09.02.2014 13:05, schrieb Fred va

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-09 Thread Sven Barth
On 09.02.2014 15:46, Jürgen Hestermann wrote: Am 2014-02-09 15:10, schrieb Fred van Stappen: > > if length(MyArray) > 0 then > > for x := 0 to high(MyArray) do > > MyArray[x].Free; As I have learned just recently ;-) this code could be shortened by for x := low(MyArray) to high(MyArray) d

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-09 Thread Jürgen Hestermann
Am 2014-02-09 15:10, schrieb Fred van Stappen: > > if length(MyArray) > 0 then > > for x := 0 to high(MyArray) do > > MyArray[x].Free; As I have learned just recently ;-) this code could be shortened by for x := low(MyArray) to high(MyArray) do MyArray[x].Free; if x is a signed integer. S

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-09 Thread Fred van Stappen
> Date: Sun, 9 Feb 2014 13:08:16 +0100 > From: freepas...@ypa-software.de > To: fpc-pascal@lists.freepascal.org > Subject: Re: [fpc-pascal] High() and Low() for empty dynamic arrays > > Am 09.02.2014 13:05, schrieb Fred van Stappen: > > if length(MyArray) > 0 th

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-09 Thread Michael Fuchs
Am 09.02.2014 13:05, schrieb Fred van Stappen: > if length(MyArray) > 0 then > for x := 0 to high(MyArray) do > MyArray[x].Free; > > But, if i use : > > setlength(MyArray, 0) ; > > would it do the same job ? No. Your array contains only references to the objects. The references where del

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-09 Thread Fred van Stappen
Hello everybody. I have a question (maybe stupid) about dynamic arrays... Usually, before to close the application, to avoid memory leak, i do : if length(MyArray) > 0 then for x := 0 to high(MyArray) do MyArray[x].Free; But, if i use : setlength(MyArray, 0) ; would it do the same job ?

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-09 Thread Saunders, Rich
On 2014-02-09 04:11, Jürgen Hestermann wrote: Am 2014-02-08 19:53, schrieb Florian Klämpfl: You didn't have only a question but you made also a proposal for a language change. And when proposing a change it is very usefull to have an example which demonstrates the reason for the change. [sni

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-09 Thread Jürgen Hestermann
Am 2014-02-08 19:53, schrieb Florian Klämpfl: > You didn't have only a question but you made also a proposal for a > language change. And when proposing a change it is very usefull to have > an example which demonstrates the reason for the change. What code should I have written? I was convinced

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-08 Thread Florian Klämpfl
Am 08.02.2014 18:06, schrieb Jürgen Hestermann: > > Am 2014-02-08 17:40, schrieb Florian Klaempfl: >> >>> You mean I should post thousands of code lines? >> >> Of course not, just a small example as I did. >> > > But for what reason? > It just generates work without benefit. > > If I had doubts

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-08 Thread Sven Barth
Am 08.02.2014 18:06 schrieb "Jürgen Hestermann" : > > > Am 2014-02-08 17:40, schrieb Florian Klaempfl: > >> >>> You mean I should post thousands of code lines? >> >> >> Of course not, just a small example as I did. >> > > But for what reason? > It just generates work without benefit. > > If I had d

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-08 Thread Jürgen Hestermann
Am 2014-02-08 17:40, schrieb Florian Klaempfl: You mean I should post thousands of code lines? Of course not, just a small example as I did. But for what reason? It just generates work without benefit. If I had doubts about my assumption regarding High and Low I would not have asked my q

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-08 Thread Florian Klaempfl
Am 08.02.2014 17:35, schrieb Jürgen Hestermann: > Unfortunatly you posted not a complete example which shows the behaviour but only uncompilable code snippts. > Post always complete examples when discussing strange behaviour. You mean I should post thousands of code lines? Of course not, ju

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-08 Thread Michael Van Canneyt
On Sat, 8 Feb 2014, leledumbo wrote: Here: var MyArray : array of longint; begin writeln(low(MyArray)); writeln(high(MyArray)); end. prints 0 -1 Is this (High() on empty dynamic arrays return -1) documented somewhere? It is now, in the system unit documentation for the High() fun

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-08 Thread Jürgen Hestermann
Am 2014-02-08 17:05, schrieb Florian Klaempfl: > Here: > var MyArray : array of longint; > begin > writeln(low(MyArray)); > writeln(high(MyArray)); > end. > prints > 0 > -1 Hmm. I was under the impression that both give back zero. But you are right. A closer look showed that the error I got f

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-08 Thread leledumbo
> Here: > > var MyArray : array of longint; > > begin >writeln(low(MyArray)); >writeln(high(MyArray)); > end. > > prints > > 0 > -1 Is this (High() on empty dynamic arrays return -1) documented somewhere? -- View this message in context: http://free-pascal-general.1045716.n5.nabble

Re: [fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-08 Thread Florian Klaempfl
Am 08.02.2014 16:56, schrieb Jürgen Hestermann: because otherwise I would get an error in case the length is 0 because Low() and High() both give back 0. The result of both functions is the same as if the array had exact one element. Here: var MyArray : array of longint; begin writeln(low(

[fpc-pascal] High() and Low() for empty dynamic arrays

2014-02-08 Thread Jürgen Hestermann
Some time ago there was a discussion about the data type given back by the "length" function. Several reasons were given for the type beeing a *signed* integer. But what about High() and Low()? Shouldn't they give back signed integers too for the same reasons? Especially, when I have a dynamic a