[fpc-pascal] Array clearing

Jürgen Hestermann juergen.hestermann at gmx.de
Thu Apr 13 11:10:38 CEST 2017


Am 2017-04-12 um 16:30 schrieb Ryan Joseph:
 >> Array[High(Array)] := whateveryouwant;

 > SetLength(Array,Length(Array)+1);
 > Array[High(Array)] := …
 > In the real world is anyone actually going to type that out every time?

Yes, I do this. Typing is not much work for me.
My main focus is on *readable* code (effort for writing is of low priority).
And the 2 lines show very clear what realy happens.

I can also omit the second line and set a value later
while with an Add-function I have to specify a value
for the new array element even if I just want to extend the array only.
I have finer control about what happens.

 > I’d bet most of us have an array class we use and ignore dynamic arrays all together because we all need basic operations like “add” and “remove”.

I never use classes.
I like dynamic arrays very much.





More information about the fpc-pascal mailing list